home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / gepackte_disketten / 1994 / 08_94_5.dms / 08_94_5.adf / term-4.0-Source.lha / termInit.c < prev    next >
C/C++ Source or Header  |  1994-07-15  |  98KB  |  4,598 lines

  1. /*
  2. **    termInit.c
  3. **
  4. **    Program initialization and shutdown routines
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11. #include "termEmulationProcess.h"
  12.  
  13.     /* Spread a byte across a long word. */
  14.  
  15. #define SPREAD(i)    ((ULONG)(i) << 24 | (ULONG)(i) << 16 | (ULONG)(i) << 8 | (i))
  16.  
  17.     /* This variable helps us to remember whether the fast!
  18.      * macro panel was open or not.
  19.      */
  20.  
  21. STATIC BYTE HadFastMacros = FALSE;
  22.  
  23.     /* Remember whether we did pen allocation or not. */
  24.  
  25. STATIC BYTE AllocatedPens = FALSE;
  26.  
  27.     /* DeleteInterleavedBitMap():
  28.      *
  29.      *    Delete an interleaved bitmap as allocated by
  30.      *    CreateInterleavedBitMap().
  31.      */
  32.  
  33. STATIC VOID __regargs
  34. DeleteInterleavedBitMap(struct BitMap *SomeBitMap)
  35. {
  36.     WaitBlit();
  37.  
  38.     FreeVec(SomeBitMap -> Planes[0]);
  39.  
  40.     FreeVecPooled(SomeBitMap);
  41. }
  42.  
  43.     /* CreateInterleavedBitMap():
  44.      *
  45.      *    With special thanks to Leo Schwab, this routine will create an
  46.      *    interleaved BitMap structure suitable for optimized blitter
  47.      *    access.
  48.      */
  49.  
  50. STATIC struct BitMap * __regargs
  51. CreateInterleavedBitMap(LONG Width,LONG Height,WORD Depth)
  52. {
  53.         /* A single plane BitMap cannot be interleaved. */
  54.  
  55.     if(Depth > 1)
  56.     {
  57.         struct BitMap *SomeBitMap;
  58.  
  59.             /* Allocate space for the bitmap structure. */
  60.  
  61.         if(SomeBitMap = (struct BitMap *)AllocVecPooled(sizeof(struct BitMap),MEMF_ANY))
  62.         {
  63.                 /* Initialize with standard values, so we can check
  64.                  * whether the current system will be able to handle
  65.                  * an interleaved bitmap of the expected size.
  66.                  */
  67.  
  68.             InitBitMap(SomeBitMap,Depth,Width,Height);
  69.  
  70.                 /* Check for old standard blitter limits. */
  71.  
  72.             if(Height * Depth > 1024 || SomeBitMap -> BytesPerRow * Depth > 126)
  73.             {
  74.                     /* The current space requirements will operate
  75.                      * correctly only on a system equipped with a
  76.                      * Fat Agnus (or successor) chip, let's see
  77.                      * if we can find one.
  78.                      */
  79.  
  80.                 if(GfxBase -> ChipRevBits0 & GFXF_BIG_BLITS)
  81.                 {
  82.                         /* Unlikely, put still not impossible: check for
  83.                          * Fat Agnus size limits...
  84.                          */
  85.  
  86.                     if(Height * Depth > 32768 || SomeBitMap -> BytesPerRow * Depth > 4096)
  87.                     {
  88.                         FreeVecPooled(SomeBitMap);
  89.  
  90.                         return(NULL);
  91.                     }
  92.                 }
  93.                 else
  94.                 {
  95.                         /* Looks like a Big or old (A1000)
  96.                          * Agnus chip.
  97.                          */
  98.  
  99.                     FreeVecPooled(SomeBitMap);
  100.  
  101.                     return(NULL);
  102.                 }
  103.             }
  104.  
  105.                 /* Initialize to interleaved BitMap values. */
  106.  
  107.             InitBitMap(SomeBitMap,1,Width,Height * Depth);
  108.  
  109.                 /* Allocate plane data. */
  110.  
  111.             if(SomeBitMap -> Planes[0] = (PLANEPTR)AllocVec(SomeBitMap -> BytesPerRow * SomeBitMap -> Rows,MEMF_CHIP))
  112.             {
  113.                 PLANEPTR    Base;
  114.                 WORD        i,
  115.                         Size;
  116.  
  117.                     /* Remember previous data. */
  118.  
  119.                 Base = SomeBitMap -> Planes[0];
  120.                 Size = SomeBitMap -> BytesPerRow;
  121.  
  122.                     /* Clear the bitmap. */
  123.  
  124.                 BltBitMap(SomeBitMap,0,0,SomeBitMap,0,0,Width,Height,MINTERM_ZERO,~0,NULL);
  125.  
  126.                     /* Reinitialize. */
  127.  
  128.                 InitBitMap(SomeBitMap,Depth,Width,Height);
  129.  
  130.                     /* Modify for interleaved look. */
  131.  
  132.                 SomeBitMap -> BytesPerRow *= Depth;
  133.  
  134.                     /* Initialize the single planes. */
  135.  
  136.                 for(i = 0 ; i < Depth ; i++)
  137.                 {
  138.                     SomeBitMap -> Planes[i] = Base;
  139.  
  140.                     Base += Size;
  141.                 }
  142.  
  143.                     /* Return the ready bitmap. */
  144.  
  145.                 return(SomeBitMap);
  146.             }
  147.  
  148.                 /* Deallocate memory. */
  149.  
  150.             FreeVecPooled(SomeBitMap);
  151.         }
  152.     }
  153.  
  154.         /* Return failure. */
  155.  
  156.     return(NULL);
  157. }
  158.  
  159.     /* LoadKeyMap(STRPTR Name):
  160.      *
  161.      *    Load a keymap file from disk.
  162.      */
  163.  
  164. STATIC struct KeyMap * __regargs
  165. LoadKeyMap(STRPTR Name)
  166. {
  167.     struct KeyMapResource    *KeyMapResource;
  168.     struct KeyMap        *Map = NULL;
  169.  
  170.         /* Try to get access to the list of currently loaded
  171.          * keymap files.
  172.          */
  173.  
  174.     if(KeyMapResource = (struct KeyMapResource *)OpenResource("keymap.resource"))
  175.     {
  176.         struct KeyMapNode *Node;
  177.  
  178.             /* Try to find the keymap in the list. */
  179.  
  180.         Forbid();
  181.  
  182.         if(Node = (struct KeyMapNode *)FindName(&KeyMapResource -> kr_List,FilePart(Config -> TerminalConfig -> KeyMapFileName)))
  183.             Map = &Node -> kn_KeyMap;
  184.  
  185.         Permit();
  186.     }
  187.  
  188.         /* Still no keymap available? */
  189.  
  190.     if(!Map)
  191.     {
  192.         APTR OldPtr = ThisProcess -> pr_WindowPtr;
  193.  
  194.             /* Disable DOS requesters. */
  195.  
  196.         ThisProcess -> pr_WindowPtr = (APTR)-1;
  197.  
  198.             /* Unload the old keymap code. */
  199.  
  200.         if(KeySegment)
  201.             UnLoadSeg(KeySegment);
  202.  
  203.             /* Try to load the keymap from the
  204.              * name the user entered.
  205.              */
  206.  
  207.         if(!(KeySegment = LoadSeg(Config -> TerminalConfig -> KeyMapFileName)))
  208.         {
  209.                 /* Second try: load it from
  210.                   * the standard keymaps drawer.
  211.                   */
  212.  
  213.             strcpy(SharedBuffer,"KEYMAPS:");
  214.  
  215.             if(AddPart(SharedBuffer,FilePart(Config -> TerminalConfig -> KeyMapFileName),MAX_FILENAME_LENGTH))
  216.             {
  217.                 if(!(KeySegment = LoadSeg(SharedBuffer)))
  218.                 {
  219.                     strcpy(SharedBuffer,"Devs:Keymaps");
  220.  
  221.                     if(AddPart(SharedBuffer,FilePart(Config -> TerminalConfig -> KeyMapFileName),MAX_FILENAME_LENGTH))
  222.                         KeySegment = LoadSeg(SharedBuffer);
  223.                 }
  224.             }
  225.         }
  226.  
  227.             /* Did we get the keymap file? */
  228.  
  229.         if(KeySegment)
  230.         {
  231.             struct KeyMapNode *Node = (struct KeyMapNode *)&((ULONG *)BADDR(KeySegment))[1];
  232.  
  233.             Map = &Node -> kn_KeyMap;
  234.         }
  235.  
  236.             /* Enable DOS requesters again. */
  237.  
  238.         ThisProcess -> pr_WindowPtr = OldPtr;
  239.     }
  240.     else
  241.     {
  242.         if(KeySegment)
  243.         {
  244.             UnLoadSeg(KeySegment);
  245.  
  246.             KeySegment = NULL;
  247.         }
  248.     }
  249.  
  250.     return(Map);
  251. }
  252.  
  253.     /* DeleteOffsetTables(VOID):
  254.      *
  255.      *    Delete the line multiplication tables.
  256.      */
  257.  
  258. STATIC VOID
  259. DeleteOffsetTables(VOID)
  260. {
  261.     if(OffsetXTable)
  262.     {
  263.         FreeVecPooled(OffsetXTable);
  264.  
  265.         OffsetXTable = NULL;
  266.     }
  267.  
  268.     if(OffsetYTable)
  269.     {
  270.         FreeVecPooled(OffsetYTable);
  271.  
  272.         OffsetYTable = NULL;
  273.     }
  274. }
  275.  
  276.     /* CreateOffsetTables(VOID):
  277.      *
  278.      *    Allocate the line multiplication tables.
  279.      */
  280.  
  281. STATIC BYTE
  282. CreateOffsetTables(VOID)
  283. {
  284.     LONG    Width    = (Window -> WScreen -> Width  + TextFontWidth)  * 2 / TextFontWidth,
  285.         Height    = (Window -> WScreen -> Height + TextFontHeight) * 2 / TextFontHeight;
  286.  
  287.     DeleteOffsetTables();
  288.  
  289.     if(OffsetXTable = (LONG *)AllocVecPooled(Width * sizeof(LONG),MEMF_ANY))
  290.     {
  291.         if(OffsetYTable = (LONG *)AllocVecPooled(Height * sizeof(LONG),MEMF_ANY))
  292.         {
  293.             LONG i,j;
  294.  
  295.             for(i = j = 0 ; i < Width ; i++, j += TextFontWidth)
  296.                 OffsetXTable[i] = j;
  297.  
  298.             for(i = j = 0 ; i < Height ; i++, j += TextFontHeight)
  299.                 OffsetYTable[i] = j;
  300.  
  301.             return(TRUE);
  302.         }
  303.     }
  304.  
  305.     DeleteOffsetTables();
  306.  
  307.     return(FALSE);
  308. }
  309.  
  310.     /* CopyItemFlags(struct MenuItem *Src,struct MenuItem *Dst):
  311.      *
  312.      *    Copy single menu item flags from one menu strip
  313.      *    to another.
  314.      */
  315.  
  316. STATIC VOID __regargs
  317. CopyItemFlags(struct MenuItem *Src,struct MenuItem *Dst)
  318. {
  319.     while(Src && Dst)
  320.     {
  321.         if(Src -> SubItem)
  322.             CopyItemFlags(Src -> SubItem,Dst -> SubItem);
  323.  
  324.         Dst -> Flags = Src -> Flags;
  325.  
  326.         Src = Src -> NextItem;
  327.         Dst = Dst -> NextItem;
  328.     }
  329. }
  330.  
  331.     /* CopyMenuFlags(struct Menu *Src,struct Menu *Dst):
  332.      *
  333.      *    Copy menu flags from one menu strip to
  334.      *    another.
  335.      */
  336.  
  337. STATIC VOID __regargs
  338. CopyMenuFlags(struct Menu *Src,struct Menu *Dst)
  339. {
  340.     struct MenuItem *SrcItem,*DstItem;
  341.  
  342.     while(Src && Dst)
  343.     {
  344.         SrcItem = Src -> FirstItem;
  345.         DstItem = Dst -> FirstItem;
  346.  
  347.         while(SrcItem && DstItem)
  348.         {
  349.             CopyItemFlags(SrcItem,DstItem);
  350.  
  351.             SrcItem = SrcItem -> NextItem;
  352.             DstItem = DstItem -> NextItem;
  353.         }
  354.  
  355.         Src = Src -> NextMenu;
  356.         Dst = Dst -> NextMenu;
  357.     }
  358. }
  359.  
  360.     /* BuildMenu():
  361.      *
  362.      *    Create the menu strip, including quick dial menu.
  363.      */
  364.  
  365. STRPTR
  366. BuildMenu()
  367. {
  368.     struct NewMenu    *NewMenu;
  369.     struct Menu    *MenuNew;
  370.     LONG         PhoneCount = 0,
  371.              Count = 0,
  372.              i;
  373.  
  374.     BlockWindows();
  375.  
  376.         /* Clear the window menu strips. */
  377.  
  378.     if(Window)
  379.         ClearMenuStrip(Window);
  380.  
  381.     if(StatusWindow)
  382.         ClearMenuStrip(StatusWindow);
  383.  
  384.     if(FastWindow)
  385.         ClearMenuStrip(FastWindow);
  386.  
  387.         /* Count the number of menu entries in
  388.          * the base menu.
  389.          */
  390.  
  391.     while(TermMenu[Count++] . nm_Type != NM_END);
  392.  
  393.         /* Add the quick dial entries. */
  394.  
  395.     if(Phonebook)
  396.     {
  397.         for(i = 0 ; PhoneCount < DIAL_MENU_MAX && i < NumPhoneEntries ; i++)
  398.         {
  399.             if(Phonebook[i] -> Header -> QuickMenu)
  400.                 PhoneCount++;
  401.         }
  402.     }
  403.  
  404.         /* Allocate new menu prototypes. */
  405.  
  406.     if(NewMenu = (struct NewMenu *)AllocVecPooled((Count + PhoneCount) * sizeof(struct NewMenu),MEMF_ANY | MEMF_CLEAR))
  407.     {
  408.         CopyMem(TermMenu,NewMenu,Count * sizeof(struct NewMenu));
  409.  
  410.         if(PhoneCount)
  411.         {
  412.             Count--;
  413.  
  414.             PhoneCount = 0;
  415.  
  416.             FirstDialMenu = -1;
  417.  
  418.             for(i = 0 ; PhoneCount < DIAL_MENU_MAX && i < NumPhoneEntries ; i++)
  419.             {
  420.                 if(Phonebook[i] -> Header -> QuickMenu)
  421.                 {
  422.                     NewMenu[Count] . nm_Type    = NM_ITEM;
  423.                     NewMenu[Count] . nm_Label    = Phonebook[i] -> Header -> Name;
  424.                     NewMenu[Count] . nm_Flags    = CHECKIT;
  425.                     NewMenu[Count] . nm_UserData    = (APTR)(DIAL_MENU_LIMIT + i);
  426.  
  427.                     PhoneCount++;
  428.                     Count++;
  429.  
  430.                     if(FirstDialMenu == -1)
  431.                         FirstDialMenu = DIAL_MENU_LIMIT + i;
  432.                 }
  433.             }
  434.  
  435.             NewMenu[Count] . nm_Type = NM_END;
  436.         }
  437.         else
  438.             NewMenu[Count - 2] . nm_Type = NM_END;
  439.  
  440.             /* Create the menu strip. */
  441.  
  442.         if(!(MenuNew = CreateMenus(NewMenu,TAG_DONE)))
  443.         {
  444.             FreeVecPooled(NewMenu);
  445.  
  446.             goto Simple;
  447.         }
  448.  
  449.             /* Do the menu layout. */
  450.  
  451.         if(!LayoutMenus(MenuNew,VisualInfo,
  452.             GTMN_NewLookMenus,    TRUE,
  453.             GTMN_TextAttr,        &UserFont,
  454.  
  455.             AmigaGlyph ? GTMN_AmigaKey :  TAG_IGNORE, AmigaGlyph,
  456.             CheckGlyph ? GTMN_Checkmark : TAG_IGNORE, CheckGlyph,
  457.         TAG_DONE))
  458.         {
  459.             FreeVecPooled(NewMenu);
  460.  
  461.             FreeMenus(MenuNew);
  462.  
  463.             goto Simple;
  464.         }
  465.  
  466.         FreeVecPooled(NewMenu);
  467.     }
  468.     else
  469.     {
  470.             /* Create the menu strip. */
  471.  
  472. Simple:        if(!(MenuNew = CreateMenus(TermMenu,TAG_DONE)))
  473.         {
  474.             ReleaseWindows();
  475.  
  476.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_MENUS_TXT));
  477.         }
  478.  
  479.             /* Do the menu layout. */
  480.  
  481.         if(!LayoutMenus(MenuNew,VisualInfo,
  482.             AmigaGlyph ? GTMN_AmigaKey :  TAG_IGNORE, AmigaGlyph,
  483.             CheckGlyph ? GTMN_Checkmark : TAG_IGNORE, CheckGlyph,
  484.  
  485.             GTMN_NewLookMenus,    TRUE,
  486.             GTMN_TextAttr,        &UserFont,
  487.         TAG_DONE))
  488.         {
  489.             ReleaseWindows();
  490.  
  491.             FreeMenus(MenuNew);
  492.  
  493.             return(LocaleString(MSG_TERMINIT_FAILED_TO_LAYOUT_MENUS_TXT));
  494.         }
  495.     }
  496.  
  497.     if(Menu)
  498.     {
  499.         CopyMenuFlags(Menu,MenuNew);
  500.  
  501.         FreeMenus(Menu);
  502.     }
  503.  
  504.     Menu = MenuNew;
  505.  
  506.     if(Window)
  507.         SetMenuStrip(Window,Menu);
  508.  
  509.     if(StatusWindow)
  510.         SetMenuStrip(StatusWindow,Menu);
  511.  
  512.     if(FastWindow)
  513.         SetMenuStrip(FastWindow,Menu);
  514.  
  515.     ReleaseWindows();
  516.  
  517.     return(NULL);
  518. }
  519.  
  520.     /* PaletteSetup():
  521.      *
  522.      *    Set up colour palettes.
  523.      */
  524.  
  525. VOID __regargs
  526. PaletteSetup(struct Configuration *SomeConfig)
  527. {
  528.     WORD i;
  529.  
  530.     if(!SomeConfig)
  531.         SomeConfig = Config;
  532.  
  533.     CopyMem(SomeConfig -> ScreenConfig -> Colours, NormalColours    ,16 * sizeof(UWORD));
  534.     CopyMem(SomeConfig -> ScreenConfig -> Colours,&NormalColours[16],16 * sizeof(UWORD));
  535.  
  536.     CopyMem(NormalColours,BlinkColours,32 * sizeof(UWORD));
  537.  
  538.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  539.     {
  540.         case COLOUR_EIGHT:
  541.  
  542.             if(SomeConfig -> ScreenConfig -> Blinking)
  543.             {
  544.                 for(i = 0 ; i < 8 ; i++)
  545.                     BlinkColours[8 + i] = BlinkColours[0];
  546.  
  547.                 PaletteSize = 16;
  548.             }
  549.             else
  550.                 PaletteSize = 8;
  551.  
  552.             break;
  553.  
  554.         case COLOUR_SIXTEEN:
  555.  
  556.             if(Window -> WScreen -> RastPort . BitMap -> Depth >= 5 && SomeConfig -> ScreenConfig -> Blinking)
  557.             {
  558.                 for(i = 0 ; i < 16 ; i++)
  559.                     BlinkColours[16 + i] = BlinkColours[0];
  560.  
  561.                 PaletteSize = 32;
  562.             }
  563.             else
  564.                 PaletteSize = 16;
  565.  
  566.             break;
  567.  
  568.         case COLOUR_AMIGA:
  569.  
  570.             BlinkColours[3] = BlinkColours[0];
  571.  
  572.             PaletteSize = 4;
  573.  
  574.             break;
  575.  
  576.         case COLOUR_MONO:
  577.  
  578.             PaletteSize = 2;
  579.             break;
  580.     }
  581. }
  582.  
  583.     /* ResetCursorKeys(struct CursorKeys *Keys):
  584.      *
  585.      *    Reset cursor key assignments to defaults.
  586.      */
  587.  
  588. VOID __regargs
  589. ResetCursorKeys(struct CursorKeys *Keys)
  590. {
  591.     STATIC STRPTR Defaults[4] =
  592.     {
  593.         "\\e[A",
  594.         "\\e[B",
  595.         "\\e[C",
  596.         "\\e[D"
  597.     };
  598.  
  599.     WORD i,j;
  600.  
  601.     for(i = 0 ; i < 4 ; i++)
  602.     {
  603.         for(j = 0 ; j < 4 ; j++)
  604.             strcpy(Keys -> Keys[j][i],Defaults[i]);
  605.     }
  606. }
  607.  
  608.     /* ResetMacroKeys(struct MacroKeys *Keys):
  609.      *
  610.      *    Reset the macro key assignments to defaults.
  611.      */
  612.  
  613. STATIC VOID __regargs
  614. ResetMacroKeys(struct MacroKeys *Keys)
  615. {
  616.     STATIC STRPTR FunctionKeyCodes[4] =
  617.     {
  618.         "\\eOP",
  619.         "\\eOQ",
  620.         "\\eOR",
  621.         "\\eOS"
  622.     };
  623.  
  624.     WORD i;
  625.  
  626.     memset(Keys,0,sizeof(struct MacroKeys));
  627.  
  628.     for(i = 0 ; i < 4 ; i++)
  629.         strcpy(Keys -> Keys[1][i],FunctionKeyCodes[i]);
  630. }
  631.  
  632.     /* ScreenSizeStuff():
  633.      *
  634.      *    Set up the terminal screen size.
  635.      */
  636.  
  637. VOID
  638. ScreenSizeStuff()
  639. {
  640.     ObtainTerminal();
  641.  
  642.         /* Is this really the built-in emulation? */
  643.  
  644.     if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  645.     {
  646.         LONG    MaxColumns    = WindowWidth / TextFontWidth,
  647.             MaxLines    = WindowHeight / TextFontHeight,
  648.             Columns,
  649.             Lines;
  650.  
  651.             /* Drop the text area marker. */
  652.  
  653.         if(Marking)
  654.             DropMarker();
  655.  
  656.             /* Turn off the cursor. */
  657.  
  658.         ClearCursor();
  659.  
  660.             /* Set up the new screen width. */
  661.  
  662.         if(Config -> TerminalConfig -> NumColumns < 20)
  663.             Columns = MaxColumns;
  664.         else
  665.             Columns = Config -> TerminalConfig -> NumColumns;
  666.  
  667.             /* Set up the new screen height. */
  668.  
  669.         if(Config -> TerminalConfig -> NumLines < 20)
  670.             Lines = MaxLines;
  671.         else
  672.             Lines = Config -> TerminalConfig -> NumLines;
  673.  
  674.             /* More columns than we will be able to display? */
  675.  
  676.         if(Columns > MaxColumns)
  677.             Columns = MaxColumns;
  678.  
  679.             /* More lines than we will be able to display? */
  680.  
  681.         if(Lines > MaxLines)
  682.             Lines = MaxLines;
  683.  
  684.             /* Set up the central data. */
  685.  
  686.         LastColumn    = Columns - 1;
  687.         LastLine    = Lines - 1;
  688.         LastPixel    = MUL_X(Columns) - 1;
  689.  
  690.             /* Are we to clear the margin? */
  691.  
  692.         if(Columns < MaxColumns || Lines < MaxLines)
  693.         {
  694.                 /* Save the rendering attributes. */
  695.  
  696.             BackupRender();
  697.  
  698.                 /* Set the defaults. */
  699.  
  700.             SetAPen(RPort,MappedPens[0][0]);
  701.  
  702.             SetWrMsk(RPort,DepthMask);
  703.  
  704.                 /* Clear remaining columns. */
  705.  
  706.             if(Columns < MaxColumns)
  707.                 ScrollLineRectFill(RPort,MUL_X(LastColumn + 1),0,WindowWidth - 1,WindowHeight - 1);
  708.  
  709.                 /* Clear remaining lines. */
  710.  
  711.             if(Lines < MaxLines)
  712.                 ScrollLineRectFill(RPort,0,MUL_Y(LastLine + 1),WindowWidth - 1,WindowHeight - 1);
  713.  
  714.                 /* Restore rendering attributes. */
  715.  
  716.             BackupRender();
  717.         }
  718.  
  719.             /* Truncate illegal cursor position. */
  720.  
  721.         if(CursorY > LastLine)
  722.             CursorY = LastLine;
  723.  
  724.         ConFontScaleUpdate();
  725.  
  726.             /* Truncate illegal cursor position. */
  727.  
  728.         if(CursorX > LastColumn)
  729.             CursorX = LastColumn;
  730.  
  731.             /* Reset the cursor position. */
  732.  
  733.         if(Config -> EmulationConfig -> FontScale == SCALE_HALF)
  734.             CursorX *= 2;
  735.         else
  736.         {
  737.             if(PrivateConfig -> EmulationConfig -> FontScale == SCALE_HALF)
  738.                 CursorX /= 2;
  739.         }
  740.  
  741.             /* Fix scroll region button. */
  742.  
  743.         if(!RegionSet)
  744.             Bottom = LastLine;
  745.  
  746.             /* Turn the cursor back on. */
  747.  
  748.         DrawCursor();
  749.     }
  750.  
  751.     FixScreenSize = FALSE;
  752.  
  753.     ReleaseTerminal();
  754. }
  755.  
  756.     /* PubScreenStuff():
  757.      *
  758.      *    This part handles the public screen setup stuff.
  759.      */
  760.  
  761. VOID
  762. PubScreenStuff()
  763. {
  764.     if(Screen)
  765.     {
  766.             /* Are we to make our screen public? */
  767.  
  768.         if(Config -> ScreenConfig -> MakeScreenPublic)
  769.             PubScreenStatus(Screen,NULL);
  770.         else
  771.             PubScreenStatus(Screen,PSNF_PRIVATE);
  772.  
  773.             /* Are we to `shanghai' Workbench windows? */
  774.  
  775.         if(Config -> ScreenConfig -> ShanghaiWindows)
  776.         {
  777.             PublicModes |= SHANGHAI;
  778.  
  779.             SetPubScreenModes(PublicModes);
  780.  
  781.                 /* Make this the default public screen. */
  782.  
  783.             SetDefaultPubScreen(TermIDString);
  784.         }
  785.         else
  786.         {
  787.             PublicModes &= ~SHANGHAI;
  788.  
  789.             if(LockPubScreen(DefaultPubScreenName))
  790.             {
  791.                 SetDefaultPubScreen(DefaultPubScreenName);
  792.  
  793.                 UnlockPubScreen(DefaultPubScreenName,NULL);
  794.             }
  795.             else
  796.                 SetDefaultPubScreen(NULL);
  797.  
  798.             SetPubScreenModes(PublicModes);
  799.         }
  800.     }
  801.  
  802.     FixPubScreenMode = FALSE;
  803. }
  804.  
  805.     /* ConfigSetup():
  806.      *
  807.      *    Compare the current configuration with the
  808.      *    last backup and reset the serial device, terminal,
  809.      *    etc. if necessary.
  810.      */
  811.  
  812. VOID
  813. ConfigSetup()
  814. {
  815.     BYTE RasterWasEnabled = RasterEnabled;
  816.  
  817.         /* First we will take a look at the configuration
  818.          * and try to find those parts which have changed
  819.          * and require the main screen display to be
  820.          * reopened.
  821.          */
  822.  
  823.     if(PrivateConfig -> ScreenConfig -> FontHeight != Config -> ScreenConfig -> FontHeight)
  824.         ResetDisplay = TRUE;
  825.  
  826.     if(PrivateConfig -> ScreenConfig -> SplitStatus != Config -> ScreenConfig -> SplitStatus)
  827.         ResetDisplay = TRUE;
  828.  
  829.     if(PrivateConfig -> ScreenConfig -> ShareScreen != Config -> ScreenConfig -> ShareScreen)
  830.         ResetDisplay = TRUE;
  831.  
  832.     if(PrivateConfig -> ScreenConfig -> Depth != Config -> ScreenConfig -> Depth || PrivateConfig -> ScreenConfig -> OverscanType != Config -> ScreenConfig -> OverscanType)
  833.         ResetDisplay = TRUE;
  834.  
  835.     if(PrivateConfig -> ScreenConfig -> DisplayWidth != Config -> ScreenConfig -> DisplayWidth || PrivateConfig -> ScreenConfig -> DisplayHeight != Config -> ScreenConfig -> DisplayHeight)
  836.         ResetDisplay = TRUE;
  837.  
  838.     if(Stricmp(PrivateConfig -> ScreenConfig -> FontName,Config -> ScreenConfig -> FontName))
  839.         ResetDisplay = TRUE;
  840.  
  841.     if(PrivateConfig -> TerminalConfig -> FontMode != Config -> TerminalConfig -> FontMode)
  842.         ResetDisplay = TRUE;
  843.  
  844.     if(PrivateConfig -> TerminalConfig -> UseTerminalTask != Config -> TerminalConfig -> UseTerminalTask)
  845.         ResetDisplay = TRUE;
  846.  
  847.     if(PrivateConfig -> TerminalConfig -> TextFontHeight != Config -> TerminalConfig -> TextFontHeight)
  848.         ResetDisplay = TRUE;
  849.  
  850.     if(Stricmp(PrivateConfig -> TerminalConfig -> TextFontName,Config -> TerminalConfig -> TextFontName))
  851.         ResetDisplay = TRUE;
  852.  
  853.     if(PrivateConfig -> ScreenConfig -> DisplayMode != Config -> ScreenConfig -> DisplayMode || PrivateConfig -> ScreenConfig -> ColourMode != Config -> ScreenConfig -> ColourMode)
  854.         ResetDisplay = TRUE;
  855.  
  856.     if(PrivateConfig -> TerminalConfig -> IBMFontHeight != Config -> TerminalConfig -> IBMFontHeight)
  857.         ResetDisplay = TRUE;
  858.  
  859.     if(Stricmp(PrivateConfig -> TerminalConfig -> IBMFontName,Config -> TerminalConfig -> IBMFontName))
  860.         ResetDisplay = TRUE;
  861.  
  862.     if((PrivateConfig -> ScreenConfig -> ColourMode == Config -> ScreenConfig -> ColourMode) && (PrivateConfig -> ScreenConfig -> ColourMode == COLOUR_EIGHT || PrivateConfig -> ScreenConfig -> ColourMode == COLOUR_SIXTEEN))
  863.     {
  864.         if(PrivateConfig -> ScreenConfig -> Blinking != Config -> ScreenConfig -> Blinking)
  865.             ResetDisplay = TRUE;
  866.     }
  867.  
  868.     if(Kick30)
  869.     {
  870.         if(Config -> ScreenConfig -> UsePens != PrivateConfig -> ScreenConfig -> UsePens || memcmp(Config -> ScreenConfig -> PenArray,PrivateConfig -> ScreenConfig -> PenArray,sizeof(UWORD) * 12))
  871.             ResetDisplay = TRUE;
  872.     }
  873.  
  874.     if(Config -> ScreenConfig -> Depth != PrivateConfig -> ScreenConfig -> Depth)
  875.         ResetDisplay = TRUE;
  876.  
  877.     if(PrivateConfig -> ScreenConfig -> FasterLayout != Config -> ScreenConfig -> FasterLayout)
  878.         ResetDisplay = TRUE;
  879.  
  880.     if(PrivateConfig -> ScreenConfig -> StatusLine != Config -> ScreenConfig -> StatusLine)
  881.         ResetDisplay = TRUE;
  882.  
  883.     if(PrivateConfig -> ScreenConfig -> TitleBar != Config -> ScreenConfig -> TitleBar)
  884.         ResetDisplay = TRUE;
  885.  
  886.     if(PrivateConfig -> ScreenConfig -> UseWorkbench != Config -> ScreenConfig -> UseWorkbench)
  887.         ResetDisplay = TRUE;
  888.  
  889.     if(strcmp(PrivateConfig -> ScreenConfig -> PubScreenName,Config -> ScreenConfig -> PubScreenName) && Config -> ScreenConfig -> UseWorkbench)
  890.         ResetDisplay = TRUE;
  891.  
  892.         /* Now for the `harmless' actions which do not
  893.          * require to change the screen or other
  894.          * rendering data.
  895.          */
  896.  
  897.     if(!ResetDisplay)
  898.     {
  899.         if(PrivateConfig -> TerminalConfig -> NumColumns != Config -> TerminalConfig -> NumColumns || PrivateConfig -> TerminalConfig -> NumLines != Config -> TerminalConfig -> NumLines)
  900.         {
  901.             if(Config -> ScreenConfig -> UseWorkbench)
  902.             {
  903.                 UWORD    Width,
  904.                     Height;
  905.  
  906.                 if(Config -> TerminalConfig -> NumColumns < 20)
  907.                     Width = ScreenWidth;
  908.                 else
  909.                     Width = Window -> BorderLeft + TextFontWidth * Config -> TerminalConfig -> NumColumns + Window -> BorderRight;
  910.  
  911.                 if(Config -> TerminalConfig -> NumLines < 20)
  912.                     Height = ScreenHeight;
  913.                 else
  914.                     Height = Window -> BorderTop + TextFontHeight * Config -> TerminalConfig -> NumLines + Window -> BorderBottom;
  915.  
  916.                 ChangeWindowBox(Window,Window -> LeftEdge,Window -> TopEdge,Width,Height);
  917.  
  918.                 FixScreenSize = TRUE;
  919.             }
  920.             else
  921.                 ResetDisplay = TRUE;
  922.         }
  923.     }
  924.  
  925.     if(PrivateConfig -> ScreenConfig -> MakeScreenPublic != Config -> ScreenConfig -> MakeScreenPublic || PrivateConfig -> ScreenConfig -> ShanghaiWindows != Config -> ScreenConfig -> ShanghaiWindows)
  926.         PubScreenStuff();
  927.  
  928.     if(PrivateConfig -> ScreenConfig -> ColourMode == Config -> ScreenConfig -> ColourMode && memcmp(PrivateConfig -> ScreenConfig -> Colours,Config -> ScreenConfig -> Colours,sizeof(UWORD) * 16))
  929.     {
  930.         switch(Config -> ScreenConfig -> ColourMode)
  931.         {
  932.             case COLOUR_EIGHT:
  933.  
  934.                 CopyMem(Config -> ScreenConfig -> Colours,ANSIColours,16 * sizeof(UWORD));
  935.                 break;
  936.  
  937.             case COLOUR_SIXTEEN:
  938.  
  939.                 CopyMem(Config -> ScreenConfig -> Colours,EGAColours,16 * sizeof(UWORD));
  940.                 break;
  941.  
  942.             case COLOUR_AMIGA:
  943.  
  944.                 CopyMem(Config -> ScreenConfig -> Colours,DefaultColours,16 * sizeof(UWORD));
  945.                 break;
  946.  
  947.             case COLOUR_MONO:
  948.  
  949.                 CopyMem(Config -> ScreenConfig -> Colours,AtomicColours,16 * sizeof(UWORD));
  950.                 break;
  951.         }
  952.     }
  953.  
  954.         /* Are we to load a new transfer library? */
  955.  
  956.     if(Config -> TransferConfig -> DefaultLibrary[0] && strcmp(PrivateConfig -> TransferConfig -> DefaultLibrary,Config -> TransferConfig -> DefaultLibrary))
  957.     {
  958.         strcpy(LastXprLibrary,Config -> TransferConfig -> DefaultLibrary);
  959.  
  960.         ProtocolSetup(FALSE);
  961.     }
  962.  
  963.         /* No custom keymap this time? */
  964.  
  965.     if(!Config -> TerminalConfig -> KeyMapFileName[0])
  966.     {
  967.         KeyMap = NULL;
  968.  
  969.         if(KeySegment)
  970.         {
  971.             UnLoadSeg(KeySegment);
  972.  
  973.             KeySegment = NULL;
  974.         }
  975.     }
  976.     else
  977.     {
  978.             /* Check whether the keymap name has changed. */
  979.  
  980.         if(strcmp(PrivateConfig -> TerminalConfig -> KeyMapFileName,Config -> TerminalConfig -> KeyMapFileName))
  981.             KeyMap = LoadKeyMap(Config -> TerminalConfig -> KeyMapFileName);
  982.     }
  983.  
  984.         /* Are we to load the keyboard macro settings? */
  985.  
  986.     if(Config -> FileConfig -> MacroFileName[0] && Stricmp(PrivateConfig -> FileConfig -> MacroFileName,Config -> FileConfig -> MacroFileName))
  987.     {
  988.         if(!LoadMacros(Config -> FileConfig -> MacroFileName,MacroKeys))
  989.             ResetMacroKeys(MacroKeys);
  990.         else
  991.             strcpy(LastMacros,Config -> FileConfig -> MacroFileName);
  992.     }
  993.  
  994.         /* Are we to load the cursor key settings? */
  995.  
  996.     if(Config -> FileConfig -> CursorFileName[0] && Stricmp(PrivateConfig -> FileConfig -> CursorFileName,Config -> FileConfig -> CursorFileName))
  997.     {
  998.         if(!ReadIFFData(Config -> FileConfig -> CursorFileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  999.             ResetCursorKeys(CursorKeys);
  1000.         else
  1001.             strcpy(LastCursorKeys,Config -> FileConfig -> CursorFileName);
  1002.     }
  1003.  
  1004.         /* Are we to load the translation tables? */
  1005.  
  1006.     if(Config -> FileConfig -> TranslationFileName[0] && Stricmp(PrivateConfig -> FileConfig -> TranslationFileName,Config -> FileConfig -> TranslationFileName))
  1007.     {
  1008.         if(SendTable)
  1009.         {
  1010.             FreeTranslationTable(SendTable);
  1011.  
  1012.             SendTable = NULL;
  1013.         }
  1014.  
  1015.         if(ReceiveTable)
  1016.         {
  1017.             FreeTranslationTable(ReceiveTable);
  1018.  
  1019.             ReceiveTable = NULL;
  1020.         }
  1021.  
  1022.         if(SendTable = AllocTranslationTable())
  1023.         {
  1024.             if(ReceiveTable = AllocTranslationTable())
  1025.             {
  1026.                 if(LoadTranslationTables(Config -> FileConfig -> TranslationFileName,SendTable,ReceiveTable))
  1027.                 {
  1028.                     strcpy(LastTranslation,Config -> FileConfig -> TranslationFileName);
  1029.  
  1030.                     if(IsStandardTable(SendTable) && IsStandardTable(ReceiveTable))
  1031.                     {
  1032.                         FreeTranslationTable(SendTable);
  1033.  
  1034.                         SendTable = NULL;
  1035.  
  1036.                         FreeTranslationTable(ReceiveTable);
  1037.  
  1038.                         ReceiveTable = NULL;
  1039.                     }
  1040.                 }
  1041.                 else
  1042.                 {
  1043.                     FreeTranslationTable(SendTable);
  1044.  
  1045.                     SendTable = NULL;
  1046.  
  1047.                     FreeTranslationTable(ReceiveTable);
  1048.  
  1049.                     ReceiveTable = NULL;
  1050.                 }
  1051.             }
  1052.             else
  1053.             {
  1054.                 FreeTranslationTable(SendTable);
  1055.  
  1056.                 SendTable = NULL;
  1057.             }
  1058.         }
  1059.     }
  1060.  
  1061.         /* Update the text sending functions. */
  1062.  
  1063.     SendSetup();
  1064.  
  1065.         /* Are we to load the fast macro settings? */
  1066.  
  1067.     if(Config -> FileConfig -> FastMacroFileName[0] && Stricmp(PrivateConfig -> FileConfig -> FastMacroFileName,Config -> FileConfig -> FastMacroFileName))
  1068.     {
  1069.         if(LoadFastMacros(Config -> FileConfig -> FastMacroFileName))
  1070.             strcpy(LastFastMacros,Config -> FileConfig -> FastMacroFileName);
  1071.     }
  1072.  
  1073.         /* Serial configuration needs updating? */
  1074.  
  1075.     ReconfigureSerial(Window,NULL);
  1076.  
  1077.         /* Are we to open the fast macro panel? */
  1078.  
  1079.     if(Config -> MiscConfig -> OpenFastMacroPanel)
  1080.         HadFastMacros = TRUE;
  1081.  
  1082.         /* Are we to freeze the text buffer? */
  1083.  
  1084.     if(!Config -> CaptureConfig -> BufferEnabled)
  1085.         BufferFrozen = TRUE;
  1086.  
  1087.         /* Now for the actions which require that the
  1088.          * screen stays open.
  1089.          */
  1090.  
  1091.     if(!ResetDisplay)
  1092.     {
  1093.         if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1094.         {
  1095.             if(PrivateConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL || (Config -> TerminalConfig -> EmulationFileName[0] && strcmp(PrivateConfig -> TerminalConfig -> EmulationFileName,Config -> TerminalConfig -> EmulationFileName)))
  1096.             {
  1097.                 if(!OpenEmulator(Config -> TerminalConfig -> EmulationFileName))
  1098.                 {
  1099.                     Config -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
  1100.  
  1101.                     ResetDisplay = TRUE;
  1102.  
  1103.                     RasterEnabled = TRUE;
  1104.  
  1105.                     MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Config -> TerminalConfig -> EmulationFileName);
  1106.                 }
  1107.                 else
  1108.                     RasterEnabled = FALSE;
  1109.             }
  1110.         }
  1111.         else
  1112.         {
  1113.             if(XEmulatorBase && PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1114.             {
  1115.                 XEmulatorClearConsole(XEM_IO);
  1116.  
  1117.                 CloseEmulator();
  1118.  
  1119.                 RasterEnabled = TRUE;
  1120.  
  1121.                 ClearCursor();
  1122.  
  1123.                 Reset();
  1124.  
  1125.                 DrawCursor();
  1126.             }
  1127.             else
  1128.                 RasterEnabled = TRUE;
  1129.         }
  1130.  
  1131.         if(RasterEnabled != RasterWasEnabled)
  1132.             RasterEraseScreen(2);
  1133.  
  1134.         if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  1135.         {
  1136.             PaletteSetup(Config);
  1137.  
  1138.             LoadRGB4(VPort,NormalColours,PaletteSize);
  1139.         }
  1140.  
  1141.         if(Config -> MiscConfig -> OpenFastMacroPanel && !FastWindow)
  1142.             OpenFastWindow();
  1143.  
  1144.         PubScreenStuff();
  1145.  
  1146.         if(Menu)
  1147.         {
  1148.             CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  1149.  
  1150.             if(!XProtocolBase)
  1151.                 SetTransferMenu(FALSE);
  1152.             else
  1153.                 SetTransferMenu(TRUE);
  1154.  
  1155.             SetRasterMenu(RasterEnabled);
  1156.         }
  1157.  
  1158.         Blocking = FALSE;
  1159.     }
  1160.     else
  1161.     {
  1162.             /* Are we no longer to use the external emulator? */
  1163.  
  1164.         if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  1165.         {
  1166.             if(XEmulatorBase && PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1167.             {
  1168.                 XEmulatorClearConsole(XEM_IO);
  1169.  
  1170.                 CloseEmulator();
  1171.             }
  1172.         }
  1173.  
  1174.         RasterEnabled = TRUE;
  1175.     }
  1176.  
  1177.         /* Change the task priority. */
  1178.  
  1179.     SetTaskPri(ThisProcess,(LONG)Config -> MiscConfig -> Priority);
  1180.  
  1181.     ConOutputUpdate();
  1182.  
  1183.     ConFontScaleUpdate();
  1184.  
  1185.     ConProcessUpdate();
  1186.  
  1187.         /* Reset the scanner. */
  1188.  
  1189.     FlowInit(TRUE);
  1190. }
  1191.  
  1192.     /* DisplayReset():
  1193.      *
  1194.      *    Reset the entire display if necessary.
  1195.      */
  1196.  
  1197. BYTE
  1198. DisplayReset()
  1199. {
  1200.     UBYTE    *Result;
  1201.     BYTE     Success = TRUE;
  1202.  
  1203.         /* Delete the display (if possible).
  1204.          * This will go wrong if there
  1205.          * are any visitor windows on our
  1206.          * screen.
  1207.          */
  1208.  
  1209.     if(DeleteDisplay())
  1210.     {
  1211.         if(Result = CreateDisplay(FALSE))
  1212.         {
  1213.             DeleteDisplay();
  1214.  
  1215.             MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Result);
  1216.  
  1217.             Success = FALSE;
  1218.         }
  1219.         else
  1220.         {
  1221.             BumpWindow(Window);
  1222.  
  1223.             PubScreenStuff();
  1224.  
  1225.             DisplayReopened = TRUE;
  1226.         }
  1227.     }
  1228.     else
  1229.     {
  1230.         SaveConfig(PrivateConfig,Config);
  1231.  
  1232.         BlockWindows();
  1233.  
  1234.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT));
  1235.  
  1236.         ReleaseWindows();
  1237.  
  1238.         Success = TRUE;
  1239.     }
  1240.  
  1241.     ResetDisplay = FALSE;
  1242.  
  1243.         /* Prepare for the worst case... */
  1244.  
  1245.     if(Success)
  1246.         Apocalypse = FALSE;
  1247.     else
  1248.         MainTerminated = Apocalypse = TRUE;
  1249.  
  1250.     return(Success);
  1251. }
  1252.  
  1253.     /* DeleteDisplay():
  1254.      *
  1255.      *    Free all resources associated with the terminal
  1256.      *    display (tasks, interrupts, screen, window, etc.).
  1257.      */
  1258.  
  1259. BYTE
  1260. DeleteDisplay()
  1261. {
  1262.     GuideCleanup();
  1263.  
  1264.     if(Screen)
  1265.     {
  1266.         struct List        *PubScreenList;
  1267.         struct PubScreenNode    *ScreenNode;
  1268.  
  1269.         PubScreenList = LockPubScreenList();
  1270.  
  1271.         for(ScreenNode = (struct PubScreenNode *)PubScreenList -> lh_Head ; ScreenNode -> psn_Node . ln_Succ ; ScreenNode = (struct PubScreenNode *)ScreenNode -> psn_Node . ln_Succ)
  1272.         {
  1273.             if(ScreenNode -> psn_Screen == Screen)
  1274.                 break;
  1275.         }
  1276.  
  1277.         if(ScreenNode && ScreenNode -> psn_Node . ln_Succ)
  1278.         {
  1279.             if(ScreenNode -> psn_VisitorCount)
  1280.             {
  1281.                 UnlockPubScreenList();
  1282.  
  1283.                 return(FALSE);
  1284.             }
  1285.             else
  1286.             {
  1287.                 Forbid();
  1288.  
  1289.                 UnlockPubScreenList();
  1290.  
  1291.                 PubScreenStatus(Screen,PSNF_PRIVATE);
  1292.  
  1293.                 Permit();
  1294.             }
  1295.         }
  1296.         else
  1297.             UnlockPubScreenList();
  1298.     }
  1299.  
  1300.     if(SharedScreen)
  1301.     {
  1302.         struct List        *PubScreenList;
  1303.         struct PubScreenNode    *ScreenNode;
  1304.  
  1305.         PubScreenList = LockPubScreenList();
  1306.  
  1307.         for(ScreenNode = (struct PubScreenNode *)PubScreenList -> lh_Head ; ScreenNode -> psn_Node . ln_Succ ; ScreenNode = (struct PubScreenNode *)ScreenNode -> psn_Node . ln_Succ)
  1308.         {
  1309.             if(ScreenNode -> psn_Screen == SharedScreen)
  1310.                 break;
  1311.         }
  1312.  
  1313.         if(ScreenNode && ScreenNode -> psn_Node . ln_Succ)
  1314.         {
  1315.             if(ScreenNode -> psn_VisitorCount)
  1316.             {
  1317.                 UnlockPubScreenList();
  1318.  
  1319.                 return(FALSE);
  1320.             }
  1321.             else
  1322.             {
  1323.                 Forbid();
  1324.  
  1325.                 UnlockPubScreenList();
  1326.  
  1327.                 PubScreenStatus(SharedScreen,PSNF_PRIVATE);
  1328.  
  1329.                 Permit();
  1330.             }
  1331.         }
  1332.         else
  1333.             UnlockPubScreenList();
  1334.     }
  1335.  
  1336.     CloseQueueWindow();
  1337.  
  1338.     if(StatusProcess)
  1339.     {
  1340.         Forbid();
  1341.  
  1342.         Signal(StatusProcess,SIG_KILL);
  1343.  
  1344.         ClrSignal(SIG_HANDSHAKE);
  1345.  
  1346.         Wait(SIG_HANDSHAKE);
  1347.  
  1348.         Permit();
  1349.  
  1350.         StatusProcess = NULL;
  1351.     }
  1352.  
  1353.     if(Marking)
  1354.         FreeMarker();
  1355.  
  1356.     FirstClick    = TRUE;
  1357.     HoldClick    = FALSE;
  1358.  
  1359.     CloseInfoWindow();
  1360.  
  1361.     DeleteReview();
  1362.  
  1363.     DeleteEmulationProcess();
  1364.  
  1365.     if(Config)
  1366.     {
  1367.         if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && XEmulatorBase)
  1368.             CloseEmulator();
  1369.     }
  1370.  
  1371.     DeleteRaster();
  1372.  
  1373.     DeleteScale();
  1374.  
  1375.     if(TabStops)
  1376.     {
  1377.         FreeVecPooled(TabStops);
  1378.  
  1379.         TabStops = NULL;
  1380.     }
  1381.  
  1382.     if(ScrollLines)
  1383.     {
  1384.         FreeVecPooled(ScrollLines);
  1385.  
  1386.         ScrollLines = NULL;
  1387.     }
  1388.  
  1389.     if(Screen)
  1390.         ScreenToBack(Screen);
  1391.  
  1392.     if(FastWindow)
  1393.     {
  1394.         HadFastMacros = TRUE;
  1395.  
  1396.         CloseFastWindow();
  1397.     }
  1398.     else
  1399.         HadFastMacros = FALSE;
  1400.  
  1401.         /* Clean up the menu glyphs. */
  1402.  
  1403.     DisposeObject(AmigaGlyph);
  1404.  
  1405.     AmigaGlyph = NULL;
  1406.  
  1407.     DisposeObject(CheckGlyph);
  1408.  
  1409.     CheckGlyph = NULL;
  1410.  
  1411.     if(StatusWindow)
  1412.     {
  1413.         ClearMenuStrip(StatusWindow);
  1414.         CloseWindowSafely(StatusWindow);
  1415.  
  1416.         StatusWindow = NULL;
  1417.     }
  1418.  
  1419.     if(DefaultPubScreen)
  1420.     {
  1421.         UnlockPubScreen(NULL,DefaultPubScreen);
  1422.  
  1423.         DefaultPubScreen = NULL;
  1424.     }
  1425.  
  1426.         /* Remove AppWindow link. */
  1427.  
  1428.     if(WorkbenchWindow)
  1429.     {
  1430.         RemoveAppWindow(WorkbenchWindow);
  1431.  
  1432.         WorkbenchWindow = NULL;
  1433.     }
  1434.  
  1435.         /* Remove AppWindow port and any pending messages. */
  1436.  
  1437.     if(WorkbenchPort)
  1438.     {
  1439.         struct Message *Message;
  1440.  
  1441.         while(Message = GetMsg(WorkbenchPort))
  1442.             ReplyMsg(Message);
  1443.  
  1444.         DeleteMsgPort(WorkbenchPort);
  1445.  
  1446.         WorkbenchPort = NULL;
  1447.     }
  1448.  
  1449.     if(DrawInfo)
  1450.     {
  1451.             /* Release the rendering pens. */
  1452.  
  1453.         FreeScreenDrawInfo(Window -> WScreen,DrawInfo);
  1454.  
  1455.         DrawInfo = NULL;
  1456.     }
  1457.  
  1458.     if(Window)
  1459.     {
  1460.         if(AllocatedPens && Kick30)
  1461.         {
  1462.             WORD i;
  1463.  
  1464.             ObtainTerminal();
  1465.  
  1466.                 /* Erase the window contents. We will
  1467.                  * want to release any pens we have
  1468.                  * allocated and want to avoid nasty
  1469.                  * flashing and flickering.
  1470.                  */
  1471.  
  1472.             SetAPen(RPort,0);
  1473.  
  1474.             RectFill(RPort,WindowLeft,WindowTop,WindowLeft + WindowWidth - 1,WindowTop + WindowHeight - 1);
  1475.  
  1476.                 /* Release any pens we have allocated. */
  1477.  
  1478.             for(i = 0 ; i < 16 ; i++)
  1479.             {
  1480.                 if(MappedPens[1][i])
  1481.                 {
  1482.                     ReleasePen(VPort -> ColorMap,MappedPens[0][i]);
  1483.  
  1484.                     MappedPens[0][i] = i;
  1485.                     MappedPens[1][i] = FALSE;
  1486.                 }
  1487.             }
  1488.  
  1489.             AllocatedPens = FALSE;
  1490.  
  1491.             ReleaseTerminal();
  1492.         }
  1493.  
  1494.         if(ClipRegion)
  1495.         {
  1496.             InstallClipRegion(Window -> WLayer,OldRegion);
  1497.  
  1498.             DisposeRegion(ClipRegion);
  1499.  
  1500.             ClipRegion = NULL;
  1501.         }
  1502.  
  1503.         ClearMenuStrip(Window);
  1504.  
  1505.         ThisProcess -> pr_WindowPtr = OldWindowPtr;
  1506.  
  1507.         PopWindow();
  1508.  
  1509.         if(TermPort)
  1510.             TermPort -> TopWindow = NULL;
  1511.  
  1512.         LT_DeleteWindowLock(Window);
  1513.  
  1514.         CloseWindow(Window);
  1515.  
  1516.         Window = NULL;
  1517.  
  1518.         if(StatusGadget)
  1519.             DeleteStatusGadget(StatusGadget);
  1520.  
  1521.         StatusGadget = NULL;
  1522.     }
  1523.  
  1524.     if(Menu)
  1525.     {
  1526.         FreeMenus(Menu);
  1527.  
  1528.         Menu = NULL;
  1529.     }
  1530.  
  1531.     if(VisualInfo)
  1532.     {
  1533.         FreeVisualInfo(VisualInfo);
  1534.  
  1535.         VisualInfo = NULL;
  1536.     }
  1537.  
  1538.     DeletePacketWindow(FALSE);
  1539.  
  1540.     if(UserTextFont)
  1541.     {
  1542.         CloseFont(UserTextFont);
  1543.  
  1544.         UserTextFont = NULL;
  1545.     }
  1546.  
  1547.         /* Before we can close screen we will have to
  1548.          * make sure that it is no longer the default
  1549.          * public screen.
  1550.          */
  1551.  
  1552.     if(Config)
  1553.     {
  1554.         if(Config -> ScreenConfig -> ShanghaiWindows)
  1555.         {
  1556.             if(LockPubScreen(DefaultPubScreenName))
  1557.             {
  1558.                 SetDefaultPubScreen(DefaultPubScreenName);
  1559.  
  1560.                 UnlockPubScreen(DefaultPubScreenName,NULL);
  1561.             }
  1562.             else
  1563.                 SetDefaultPubScreen(NULL);
  1564.         }
  1565.     }
  1566.  
  1567.     if(Screen)
  1568.     {
  1569.         CloseScreen(Screen);
  1570.  
  1571.         Screen = NULL;
  1572.     }
  1573.  
  1574.     if(SharedScreen)
  1575.     {
  1576.         CloseScreen(SharedScreen);
  1577.  
  1578.         SharedScreen = NULL;
  1579.     }
  1580.  
  1581.     if(InterleavedBitMap)
  1582.     {
  1583.         DeleteInterleavedBitMap(InterleavedBitMap);
  1584.  
  1585.         InterleavedBitMap = NULL;
  1586.     }
  1587.  
  1588.     if(GFX)
  1589.     {
  1590.         CloseFont(GFX);
  1591.  
  1592.         GFX = NULL;
  1593.     }
  1594.  
  1595.     if(TextFont)
  1596.     {
  1597.         CloseFont(TextFont);
  1598.  
  1599.         TextFont = NULL;
  1600.     }
  1601.  
  1602.     return(TRUE);
  1603. }
  1604.  
  1605. STATIC VOID __regargs
  1606. StatusSizeSetup(struct Screen *Screen,LONG *StatusWidth,LONG *StatusHeight)
  1607. {
  1608.     SZ_SizeSetup(Screen,&UserFont);
  1609.  
  1610.     if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  1611.     {
  1612.         if(Config -> ScreenConfig -> StatusLine == STATUSLINE_COMPRESSED)
  1613.         {
  1614.             *StatusWidth    = 80 * UserFontWidth;
  1615.             *StatusHeight    = UserFontHeight;
  1616.  
  1617.             if(Config -> ScreenConfig -> SplitStatus)
  1618.             {
  1619.                 *StatusWidth    += 2;
  1620.                 *StatusHeight    += 2;
  1621.             }
  1622.         }
  1623.         else
  1624.         {
  1625.             LONG    i,Len,Max;
  1626.             UWORD    ColumnLeft[4],
  1627.                 ColumnWidth[4];
  1628.  
  1629.             *StatusWidth    = 0;
  1630.             *StatusHeight    = SZ_BoxHeight(2);
  1631.  
  1632.             ColumnLeft[0] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_STATUS_TXT,MSG_TERMSTATUSDISPLAY_FONT_TXT,-1);
  1633.             ColumnLeft[1] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_PROTOCOL_TXT,MSG_TERMSTATUSDISPLAY_TERMINAL_TXT,-1);
  1634.             ColumnLeft[2] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_BAUDRATE_TXT,MSG_TERMSTATUSDISPLAY_PARAMETERS_TXT,-1);
  1635.             ColumnLeft[3] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_TIME_TXT,MSG_TERMSTATUSDISPLAY_ONLINE_TXT,-1);
  1636.  
  1637.             Max = 0;
  1638.  
  1639.             for(i = MSG_TERMAUX_READY_TXT ; i <= MSG_TERMAUX_HANG_UP_TXT ; i++)
  1640.             {
  1641.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1642.                     Max = Len;
  1643.             }
  1644.  
  1645.             for(i = MSG_TERMSTATUSDISPLAY_FROZEN_TXT ; i <= MSG_TERMSTATUSDISPLAY_RECORDING_TXT ; i++)
  1646.             {
  1647.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1648.                     Max = Len;
  1649.             }
  1650.  
  1651.             ColumnWidth[0] = Max;
  1652.  
  1653.             Max = SZ_BoxWidth(12);
  1654.  
  1655.             for(i = MSG_TERMAUX_ANSI_VT102_TXT ; i <= MSG_TERMAUX_HEX_TXT ; i++)
  1656.             {
  1657.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1658.                     Max = Len;
  1659.             }
  1660.  
  1661.             ColumnWidth[1] = Max;
  1662.  
  1663.             Max = SZ_BoxWidth(10);
  1664.  
  1665.             for(i = MSG_TERMAUX_NONE_TXT ; i <= MSG_TERMAUX_SPACE_TXT ; i++)
  1666.             {
  1667.                 if((Len = SZ_BoxWidth(4 + strlen(LocaleString(i)))) > Max)
  1668.                     Max = Len;
  1669.             }
  1670.  
  1671.             ColumnWidth[2] = Max;
  1672.  
  1673.             ColumnWidth[3] = SZ_BoxWidth(8);
  1674.  
  1675.             for(i = 0 ; i < 4 ; i++)
  1676.                 *StatusWidth += ColumnWidth[i] + ColumnLeft[i];
  1677.  
  1678.             *StatusWidth += 3 * InterWidth;
  1679.  
  1680.             if(!Config -> ScreenConfig -> SplitStatus)
  1681.                 *StatusHeight += 3;
  1682.             else
  1683.             {
  1684.                 *StatusWidth    += 2;
  1685.                 *StatusHeight    += 2;
  1686.             }
  1687.         }
  1688.     }
  1689.     else
  1690.         *StatusHeight = 0;
  1691. }
  1692.  
  1693.     /* CreateDisplay(BYTE FirstSetup):
  1694.      *
  1695.      *    Open the display and allocate associated data.
  1696.      */
  1697.  
  1698. STRPTR __regargs
  1699. CreateDisplay(BYTE FirstSetup)
  1700. {
  1701.     UWORD            Count = 0,i;
  1702.     LONG            ErrorCode,Top,Height;
  1703.     ULONG            TagArray[9];
  1704.     struct Rectangle    DisplayClip;
  1705.     BYTE            OpenFailed = FALSE,
  1706.                 RealDepth;
  1707.     STRPTR            Error;
  1708.     ULONG            X_DPI,Y_DPI;
  1709.     UWORD            PenArray[16];
  1710.     LONG            StatusWidth,
  1711.                 StatusHeight;
  1712.  
  1713.     BlockNestCount = 0;
  1714.  
  1715.     WeAreBlocking = FALSE;
  1716.  
  1717.     SetQueueDiscard(SpecialQueue,FALSE);
  1718.  
  1719.     TagDPI[0] . ti_Tag = TAG_DONE;
  1720.  
  1721.         /* Don't permit weird settings. */
  1722.  
  1723.     if(!Config -> ScreenConfig -> StatusLine || (!Config -> ScreenConfig -> ShareScreen && !Config -> ScreenConfig -> UseWorkbench))
  1724.         Config -> ScreenConfig -> SplitStatus = FALSE;
  1725.  
  1726.     if(Config -> ScreenConfig -> UseWorkbench || Config -> ScreenConfig -> ShareScreen)
  1727.     {
  1728.         STRPTR ScreenName = NULL;
  1729.  
  1730.         if(Config -> ScreenConfig -> PubScreenName[0])
  1731.         {
  1732.             struct Screen *SomeScreen;
  1733.  
  1734.             if(SomeScreen = LockPubScreen(Config -> ScreenConfig -> PubScreenName))
  1735.             {
  1736.                 UnlockPubScreen(NULL,SomeScreen);
  1737.  
  1738.                 ScreenName = Config -> ScreenConfig -> PubScreenName;
  1739.             }
  1740.         }
  1741.  
  1742.         if(!(DefaultPubScreen = LockPubScreen(ScreenName)))
  1743.             return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_DEFAULT_PUBLIC_SCREEN_TXT));
  1744.         else
  1745.         {
  1746.             GetDPI(GetVPModeID(&DefaultPubScreen -> ViewPort),&X_DPI,&Y_DPI);
  1747.  
  1748.                 /* gadtools.library v37 objects don't look too pretty
  1749.                  * with a proportional-spaced font.
  1750.                  */
  1751.  
  1752. /*            if(!(DefaultPubScreen -> Font -> ta_Flags & FPF_PROPORTIONAL) || Kick30)*/
  1753.  
  1754.             if(TRUE)
  1755.             {
  1756.                 strcpy(UserFontName,DefaultPubScreen -> Font -> ta_Name);
  1757.  
  1758.                 UserFont . tta_Name    = UserFontName;
  1759.                 UserFont . tta_YSize    = DefaultPubScreen -> Font -> ta_YSize;
  1760.                 UserFont . tta_Style    = DefaultPubScreen -> Font -> ta_Style;
  1761.                 UserFont . tta_Flags    = DefaultPubScreen -> Font -> ta_Flags;
  1762.             }
  1763.             else
  1764.             {
  1765.                 UnlockPubScreen(NULL,DefaultPubScreen);
  1766.  
  1767.                 DefaultPubScreen = NULL;
  1768.  
  1769.                 Config -> ScreenConfig -> UseWorkbench = FALSE;
  1770.             }
  1771.         }
  1772.     }
  1773.  
  1774.     if(!Config -> ScreenConfig -> UseWorkbench)
  1775.     {
  1776.         GetDPI(Config -> ScreenConfig -> DisplayMode,&X_DPI,&Y_DPI);
  1777.  
  1778.         strcpy(UserFontName,Config -> ScreenConfig -> FontName);
  1779.  
  1780.         UserFont . tta_Name    = UserFontName;
  1781.         UserFont . tta_YSize    = Config -> ScreenConfig -> FontHeight;
  1782.         UserFont . tta_Style    = FS_NORMAL | FSF_TAGGED;
  1783.         UserFont . tta_Flags    = FPF_DESIGNED;
  1784.         UserFont . tta_Tags    = TagDPI;
  1785.  
  1786.         TagDPI[0] . ti_Tag     = TA_DeviceDPI;
  1787.         TagDPI[0] . ti_Data     = (X_DPI << 16) | Y_DPI;
  1788.         TagDPI[1] . ti_Tag     = TAG_DONE;
  1789.     }
  1790.  
  1791.     if(!(UserTextFont = OpenDiskFont(&UserFont)))
  1792.     {
  1793.         if(Config -> ScreenConfig -> UseWorkbench)
  1794.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  1795.         else
  1796.         {
  1797.             strcpy(Config -> ScreenConfig -> FontName,    "topaz.font");
  1798.             strcpy(UserFontName,                "topaz.font");
  1799.  
  1800.             Config -> ScreenConfig -> FontHeight = 8;
  1801.  
  1802.             UserFont . tta_YSize    = Config -> ScreenConfig -> FontHeight;
  1803.             UserFont . tta_Style    = FS_NORMAL;
  1804.             UserFont . tta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  1805.  
  1806.             if(!(UserTextFont = OpenFont(&UserFont)))
  1807.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  1808.         }
  1809.     }
  1810.  
  1811. Reopen:    if(Config -> TerminalConfig -> FontMode != FONT_STANDARD)
  1812.     {
  1813.         strcpy(TextFontName,Config -> TerminalConfig -> IBMFontName);
  1814.  
  1815.         TextAttr . tta_YSize = Config -> TerminalConfig -> IBMFontHeight;
  1816.     }
  1817.     else
  1818.     {
  1819.         strcpy(TextFontName,Config -> TerminalConfig -> TextFontName);
  1820.  
  1821.         TextAttr . tta_YSize = Config -> TerminalConfig -> TextFontHeight;
  1822.     }
  1823.  
  1824.     TextAttr . tta_Name    = TextFontName;
  1825.     TextAttr . tta_Style    = FS_NORMAL | FSF_TAGGED;
  1826.     TextAttr . tta_Flags    = FPF_DESIGNED;
  1827.     TextAttr . tta_Tags    = TagDPI;
  1828.  
  1829.     if(!(TextFont = OpenDiskFont(&TextAttr)))
  1830.     {
  1831.         if(Config -> TerminalConfig -> FontMode != FONT_STANDARD)
  1832.         {
  1833.             Config -> TerminalConfig -> FontMode = FONT_STANDARD;
  1834.  
  1835.             goto Reopen;
  1836.         }
  1837.  
  1838.         strcpy(Config -> TerminalConfig -> TextFontName,    "topaz.font");
  1839.         strcpy(TextFontName,                    "topaz.font");
  1840.  
  1841.         Config -> TerminalConfig -> TextFontHeight = 8;
  1842.  
  1843.         TextAttr . tta_YSize    = Config -> TerminalConfig -> TextFontHeight;
  1844.         TextAttr . tta_Style    = FS_NORMAL;
  1845.         TextAttr . tta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  1846.         TextAttr . tta_Tags    = NULL;
  1847.  
  1848.         if(!(TextFont = OpenFont(&TextAttr)))
  1849.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_TEXT_TXT));
  1850.     }
  1851.  
  1852.     TextFontHeight    = TextFont -> tf_YSize;
  1853.     TextFontWidth    = TextFont -> tf_XSize;
  1854.     TextFontBase    = TextFont -> tf_Baseline;
  1855.  
  1856.         /* Determine extra font box width for slanted/boldface glyphs. */
  1857.  
  1858.     FontRightExtend    = MAX(TextFont -> tf_XSize / 2,TextFont -> tf_BoldSmear);
  1859.  
  1860.     CurrentFont = TextFont;
  1861.  
  1862.     GFXFont . ta_YSize = Config -> ScreenConfig -> FontHeight;
  1863.  
  1864.     if(GFX = (struct TextFont *)OpenDiskFont(&GFXFont))
  1865.     {
  1866.         if(GFX -> tf_XSize != TextFont -> tf_XSize || GFX -> tf_YSize != TextFont -> tf_YSize)
  1867.         {
  1868.             CloseFont(GFX);
  1869.  
  1870.             GFX = NULL;
  1871.         }
  1872.     }
  1873.  
  1874.     UserFontHeight    = UserTextFont -> tf_YSize;
  1875.     UserFontWidth    = UserTextFont -> tf_XSize;
  1876.     UserFontBase    = UserTextFont -> tf_Baseline;
  1877.  
  1878.     if(Config -> ScreenConfig -> UseWorkbench || Config -> ScreenConfig -> ShareScreen)
  1879.     {
  1880.         struct TagItem     SomeTags[7];
  1881.         LONG         FullWidth,
  1882.                  Height,Width,
  1883.                  Index = 0;
  1884.         struct Screen    *LocalScreen = DefaultPubScreen;
  1885.  
  1886.         if(Config -> ScreenConfig -> ShareScreen && !Config -> ScreenConfig -> UseWorkbench)
  1887.         {
  1888.             struct DimensionInfo DimensionInfo;
  1889.  
  1890.             if(ModeNotAvailable(Config -> ScreenConfig -> DisplayMode))
  1891.                 Config -> ScreenConfig -> DisplayMode = GetVPModeID(&DefaultPubScreen -> ViewPort);
  1892.  
  1893.             if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  1894.             {
  1895.                 LONG    Depth,ScreenWidth,ScreenHeight;
  1896.                 UWORD    Pens = (UWORD)~0;
  1897.  
  1898.                 if(Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayHeight)
  1899.                 {
  1900.                     ScreenWidth    = Config -> ScreenConfig -> DisplayWidth;
  1901.                     ScreenHeight    = Config -> ScreenConfig -> DisplayHeight;
  1902.                 }
  1903.                 else
  1904.                 {
  1905.                     ScreenWidth    = 0;
  1906.                     ScreenHeight    = 0;
  1907.                 }
  1908.  
  1909.                 switch(Config -> ScreenConfig -> ColourMode)
  1910.                 {
  1911.                     case COLOUR_EIGHT:
  1912.  
  1913.                         Depth = 3;
  1914.                         break;
  1915.  
  1916.                     case COLOUR_SIXTEEN:
  1917.  
  1918.                         Depth = 4;
  1919.                         break;
  1920.  
  1921.                     case COLOUR_AMIGA:
  1922.  
  1923.                         Depth = 2;
  1924.                         break;
  1925.  
  1926.                     default:
  1927.  
  1928.                         Depth = 1;
  1929.                         break;
  1930.                 }
  1931.  
  1932.                 if(Depth > DimensionInfo . MaxDepth)
  1933.                     Depth = DimensionInfo . MaxDepth;
  1934.  
  1935.                 if(!Kick30 && Depth > 2)
  1936.                     Depth = 2;
  1937.  
  1938.                 if(Config -> ScreenConfig -> Depth && Config -> ScreenConfig -> Depth <= DimensionInfo . MaxDepth)
  1939.                     Depth = Config -> ScreenConfig -> Depth;
  1940.  
  1941. #ifdef _M68030
  1942.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'030 ",TermDate,TermIDString);
  1943. #else
  1944.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"",TermDate,TermIDString);
  1945. #endif    /* _M68030 */
  1946.                 if(SharedScreen = OpenScreenTags(NULL,
  1947.                     ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  1948.                     ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  1949.  
  1950.                     SA_Title,    ScreenTitle,
  1951.                     SA_Depth,    Depth,
  1952.                     SA_Pens,    &Pens,
  1953.                     SA_Overscan,    Config -> ScreenConfig -> OverscanType,
  1954.                     SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  1955.                     SA_Font,    &UserFont,
  1956.                     SA_AutoScroll,    TRUE,
  1957.                     SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  1958.                     SA_PubName,    TermIDString,
  1959.                     SA_Interleaved,    Config -> ScreenConfig -> FasterLayout && Kick30 && Depth > 1,
  1960.                     SA_SharePens,    TRUE,
  1961.                 TAG_DONE))
  1962.                 {
  1963.                     LocalScreen = SharedScreen;
  1964.  
  1965.                     if(DefaultPubScreen)
  1966.                     {
  1967.                         UnlockPubScreen(NULL,DefaultPubScreen);
  1968.  
  1969.                         DefaultPubScreen = NULL;
  1970.                     }
  1971.  
  1972.                     if(Config -> ScreenConfig -> MakeScreenPublic)
  1973.                         PubScreenStatus(LocalScreen,NULL);
  1974.                     else
  1975.                         PubScreenStatus(LocalScreen,PSNF_PRIVATE);
  1976.                 }
  1977.             }
  1978.         }
  1979.  
  1980.         if(!SharedScreen)
  1981.         {
  1982. #ifdef _M68030
  1983.             SPrintf(ScreenTitle,"%s '030 (%s)",TermName,TermDate);
  1984. #else
  1985.             SPrintf(ScreenTitle,"%s (%s)",TermName,TermDate);
  1986. #endif    /* _M68030 */
  1987.  
  1988.         }
  1989.  
  1990.         StatusSizeSetup(LocalScreen,&StatusWidth,&StatusHeight);
  1991.  
  1992.         if(LocalScreen -> RastPort . BitMap -> Depth == 1)
  1993.             UseMasking = FALSE;
  1994.         else
  1995.         {
  1996.             if(Kick30)
  1997.             {
  1998.                 if(GetBitMapAttr(LocalScreen -> RastPort . BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  1999.                     UseMasking = FALSE;
  2000.                 else
  2001.                     UseMasking = TRUE;
  2002.             }
  2003.             else
  2004.                 UseMasking = TRUE;
  2005.         }
  2006.  
  2007.         VPort = &LocalScreen -> ViewPort;
  2008.  
  2009.             /* Get the current display dimensions. */
  2010.  
  2011.         if(VPort -> ColorMap -> cm_vpe)
  2012.         {
  2013.             struct ViewPortExtra *Extra;
  2014.  
  2015.             Extra = VPort -> ColorMap -> cm_vpe;
  2016.  
  2017.             ScreenWidth    = Extra -> DisplayClip . MaxX - Extra -> DisplayClip . MinX + 1;
  2018.             ScreenHeight    = Extra -> DisplayClip . MaxY - Extra -> DisplayClip . MinY + 1;
  2019.         }
  2020.         else
  2021.         {
  2022.             struct ViewPortExtra *Extra;
  2023.  
  2024.             if(Extra = (struct ViewPortExtra *)GfxLookUp(VPort))
  2025.             {
  2026.                 ScreenWidth    = Extra -> DisplayClip . MaxX - Extra -> DisplayClip . MinX + 1;
  2027.                 ScreenHeight    = Extra -> DisplayClip . MaxY - Extra -> DisplayClip . MinY + 1;
  2028.             }
  2029.             else
  2030.             {
  2031.                 ScreenWidth    = LocalScreen -> Width;
  2032.                 ScreenHeight    = LocalScreen -> Height;
  2033.             }
  2034.         }
  2035.  
  2036.         DepthMask = (1L << LocalScreen -> RastPort . BitMap -> Depth) - 1;
  2037.  
  2038.         switch(Config -> ScreenConfig -> ColourMode)
  2039.         {
  2040.             case COLOUR_SIXTEEN:
  2041.  
  2042.                 if(DepthMask < 15)
  2043.                 {
  2044.                     if(DepthMask >= 7)
  2045.                         Config -> ScreenConfig -> ColourMode = COLOUR_EIGHT;
  2046.                     else
  2047.                     {
  2048.                         if(DepthMask >= 3)
  2049.                             Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2050.                         else
  2051.                             Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2052.                     }
  2053.                 }
  2054.  
  2055.                 break;
  2056.  
  2057.             case COLOUR_EIGHT:
  2058.  
  2059.                 if(DepthMask < 7)
  2060.                 {
  2061.                     if(DepthMask >= 3)
  2062.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2063.                     else
  2064.                         Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2065.                 }
  2066.  
  2067.                 break;
  2068.  
  2069.             case COLOUR_AMIGA:
  2070.  
  2071.                 if(DepthMask < 3)
  2072.                     Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2073.  
  2074.                 break;
  2075.         }
  2076.  
  2077.         if(!(DrawInfo = GetScreenDrawInfo(LocalScreen)))
  2078.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_SCREEN_DRAWINFO_TXT));
  2079.  
  2080.         CreateMenuGlyphs(LocalScreen,DrawInfo,&AmigaGlyph,&CheckGlyph);
  2081.  
  2082.         SZ_SizeSetup(LocalScreen,&UserFont);
  2083.  
  2084.             /* Obtain visual info (whatever that may be). */
  2085.  
  2086.         if(!(VisualInfo = GetVisualInfo(LocalScreen,TAG_DONE)))
  2087.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  2088.  
  2089.         if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !Config -> ScreenConfig -> SplitStatus)
  2090.         {
  2091.             if(!(StatusGadget = (struct Gadget *)CreateStatusGadget(LocalScreen -> Width,42)))
  2092.                 return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_STATUS_GADGET_TXT));
  2093.         }
  2094.  
  2095.         if(StatusGadget)
  2096.             GetAttr(SGA_FullWidth,StatusGadget,(ULONG *)&FullWidth);
  2097.         else
  2098.             FullWidth = 0;
  2099.  
  2100.         if(StatusGadget)
  2101.         {
  2102.             SomeTags[Index  ] . ti_Tag    = WA_Gadgets;
  2103.             SomeTags[Index++] . ti_Data    = (ULONG)StatusGadget;
  2104.         }
  2105.  
  2106.         if(WindowBox . Left != -1)
  2107.         {
  2108.             SomeTags[Index  ] . ti_Tag    = WA_Left;
  2109.             SomeTags[Index++] . ti_Data    = WindowBox . Left;
  2110.             SomeTags[Index  ] . ti_Tag    = WA_Top;
  2111.             SomeTags[Index++] . ti_Data    = WindowBox . Top;
  2112.  
  2113.             SomeTags[Index  ] . ti_Tag    = WA_Width;
  2114.             SomeTags[Index++] . ti_Data    = WindowBox . Width;
  2115.             SomeTags[Index  ] . ti_Tag    = WA_Height;
  2116.             SomeTags[Index++] . ti_Data    = WindowBox . Height;
  2117.  
  2118.             WindowBox . Left = -1;
  2119.         }
  2120.         else
  2121.         {
  2122.             if(Config -> TerminalConfig -> NumColumns < 20)
  2123.             {
  2124.                 LONG Width = GetScreenWidth(NULL);
  2125.  
  2126.                 if(FullWidth && Width < FullWidth)
  2127.                 {
  2128.                     SomeTags[Index  ] . ti_Tag    = WA_InnerWidth;
  2129.                     SomeTags[Index++] . ti_Data    = FullWidth;
  2130.                 }
  2131.                 else
  2132.                 {
  2133.                     SomeTags[Index  ] . ti_Tag    = WA_Width;
  2134.                     SomeTags[Index++] . ti_Data    = Width;
  2135.                 }
  2136.             }
  2137.             else
  2138.             {
  2139.                 SomeTags[Index  ] . ti_Tag    = WA_InnerWidth;
  2140.                 SomeTags[Index++] . ti_Data    = Config -> TerminalConfig -> NumColumns * TextFontWidth;
  2141.             }
  2142.  
  2143.             if(Config -> TerminalConfig -> NumLines < 20)
  2144.             {
  2145.                 SomeTags[Index  ] . ti_Tag    = WA_Height;
  2146.                 SomeTags[Index++] . ti_Data    = GetScreenHeight(NULL) - (LocalScreen -> BarHeight + 1);
  2147.             }
  2148.             else
  2149.             {
  2150.                 SomeTags[Index  ] . ti_Tag    = WA_InnerHeight;
  2151.                 SomeTags[Index++] . ti_Data    = Config -> TerminalConfig -> NumLines * TextFontHeight;
  2152.             }
  2153.  
  2154.             SomeTags[Index  ] . ti_Tag    = WA_Left;
  2155.             SomeTags[Index++] . ti_Data    = GetScreenLeft(NULL);
  2156.  
  2157.             SomeTags[Index  ] . ti_Tag    = WA_Top;
  2158.             SomeTags[Index++] . ti_Data    = GetScreenTop(NULL) + LocalScreen -> BarHeight + 1;
  2159.         }
  2160.  
  2161.         SomeTags[Index] . ti_Tag = TAG_DONE;
  2162.  
  2163.             /* Open the main window. */
  2164.  
  2165.         if(!(Window = OpenWindowTags(NULL,
  2166.             WA_MaxHeight,        LocalScreen -> Height,
  2167.             WA_MaxWidth,        LocalScreen -> Width,
  2168.             WA_SmartRefresh,    TRUE,
  2169.             WA_CustomScreen,    LocalScreen,
  2170.             WA_NewLookMenus,    TRUE,
  2171.             WA_RMBTrap,        TRUE,
  2172.             WA_IDCMP,        IDCMP_RAWKEY | IDCMP_INACTIVEWINDOW | IDCMP_ACTIVEWINDOW | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_IDCMPUPDATE,
  2173.             WA_DragBar,        TRUE,
  2174.             WA_DepthGadget,        TRUE,
  2175.             WA_CloseGadget,        TRUE,
  2176.             WA_SizeGadget,        TRUE,
  2177.             WA_SizeBBottom,        TRUE,
  2178.             WA_NoCareRefresh,    TRUE,
  2179.             WA_Title,        ScreenTitle,
  2180.  
  2181.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  2182.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  2183.  
  2184.             TAG_MORE,        SomeTags,
  2185.         TAG_DONE)))
  2186.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2187.  
  2188.             /* Create a user clip region to keep text from
  2189.              * leaking into the window borders.
  2190.              */
  2191.  
  2192.         if(!(ClipRegion = NewRegion()))
  2193.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2194.         else
  2195.         {
  2196.             struct Rectangle RegionRectangle;
  2197.  
  2198.                 /* Adjust the region to match the inner window area. */
  2199.  
  2200.             RegionRectangle . MinX = Window -> BorderLeft;
  2201.             RegionRectangle . MinY = Window -> BorderTop;
  2202.             RegionRectangle . MaxX = Window -> Width - (Window -> BorderRight + 1);
  2203.             RegionRectangle . MaxY = Window -> Height - (Window -> BorderBottom + 1);
  2204.  
  2205.                 /* Establish the region. */
  2206.  
  2207.             OrRectRegion(ClipRegion,&RegionRectangle);
  2208.  
  2209.                 /* Install the region. */
  2210.  
  2211.             OldRegion = InstallClipRegion(Window -> WLayer,ClipRegion);
  2212.         }
  2213.  
  2214.         if(FullWidth < 40 * TextFontWidth)
  2215.             FullWidth = 40 * TextFontWidth;
  2216.  
  2217.         Width    = Window -> BorderLeft + FullWidth + Window -> BorderRight;
  2218.         Height    = Window -> BorderTop + 20 * TextFontHeight + Window -> BorderBottom;
  2219.  
  2220.         WindowLimits(Window,Width,Height,0,0);
  2221.  
  2222.         if(WorkbenchBase)
  2223.         {
  2224.             if(WorkbenchPort = CreateMsgPort())
  2225.             {
  2226.                 if(!(WorkbenchWindow = AddAppWindow(0,0,Window,WorkbenchPort,TAG_DONE)))
  2227.                 {
  2228.                     DeleteMsgPort(WorkbenchPort);
  2229.  
  2230.                     WorkbenchPort = NULL;
  2231.                 }
  2232.             }
  2233.         }
  2234.     }
  2235.     else
  2236.     {
  2237.         struct DimensionInfo    DimensionInfo;
  2238.         WORD            MaxDepth,
  2239.                     ScreenDepth;
  2240.  
  2241.         if(ModeNotAvailable(Config -> ScreenConfig -> DisplayMode))
  2242.         {
  2243.             struct Screen *PubScreen;
  2244.  
  2245.             if(PubScreen = LockPubScreen(NULL))
  2246.             {
  2247.                 Config -> ScreenConfig -> DisplayMode = GetVPModeID(&PubScreen -> ViewPort);
  2248.  
  2249.                 UnlockPubScreen(NULL,PubScreen);
  2250.             }
  2251.         }
  2252.  
  2253.         if(!QueryOverscan(Config -> ScreenConfig -> DisplayMode,&DisplayClip,Config -> ScreenConfig -> OverscanType))
  2254.         {
  2255.             OpenFailed = TRUE;
  2256.  
  2257.             ErrorCode = ModeNotAvailable(Config -> ScreenConfig -> DisplayMode);
  2258.  
  2259.             goto OpenS;
  2260.         }
  2261.  
  2262.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2263.         {
  2264.             UWORD    MaxWidth,
  2265.                 MaxHeight,
  2266.                 Width,
  2267.                 Height;
  2268.  
  2269.             MaxWidth    = DisplayClip . MaxX - DisplayClip . MinX + 1;
  2270.             MaxHeight    = DisplayClip . MaxY - DisplayClip . MinY + 1;
  2271.  
  2272.             if(Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayHeight)
  2273.             {
  2274.                 ScreenWidth    = Config -> ScreenConfig -> DisplayWidth;
  2275.                 ScreenHeight    = Config -> ScreenConfig -> DisplayHeight;
  2276.             }
  2277.             else
  2278.             {
  2279.                 ScreenWidth    = MaxWidth;
  2280.                 ScreenHeight    = MaxHeight;
  2281.             }
  2282.  
  2283.             if(Config -> TerminalConfig -> NumColumns < 20)
  2284.                 Width = MaxWidth = ScreenWidth;
  2285.             else
  2286.             {
  2287.                 Width = TextFontWidth * Config -> TerminalConfig -> NumColumns;
  2288.  
  2289.                 ScreenWidth = 0;
  2290.             }
  2291.  
  2292.             if(Config -> TerminalConfig -> NumLines < 20)
  2293.                 Height = MaxHeight = ScreenHeight;
  2294.             else
  2295.             {
  2296.                 Height = TextFontHeight * Config -> TerminalConfig -> NumLines;
  2297.  
  2298.                 if(Config -> ScreenConfig -> TitleBar)
  2299.                     Height += UserFontHeight + 3;
  2300.  
  2301.                 if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  2302.                 {
  2303.                     if(Config -> ScreenConfig -> StatusLine == STATUSLINE_COMPRESSED)
  2304.                         Height += UserFontHeight;
  2305.                     else
  2306.                         Height += 2 + (2 + 2 * UserFontHeight + 2);
  2307.                 }
  2308.  
  2309.                 ScreenHeight = 0;
  2310.             }
  2311.  
  2312.             if(Height > MaxHeight)
  2313.                 Height = MaxHeight;
  2314.  
  2315.             if(Width > MaxWidth)
  2316.                 Width = MaxWidth;
  2317.  
  2318.             if(DimensionInfo . MinRasterWidth <= Width && Width <= DimensionInfo . MaxRasterWidth)
  2319.             {
  2320.                 UWORD Half;
  2321.  
  2322.                 Width = MaxWidth - Width;
  2323.  
  2324.                 Half = Width / 2;
  2325.  
  2326.                 DisplayClip . MinX += Half;
  2327.                 DisplayClip . MaxX -= Width - Half;
  2328.             }
  2329.  
  2330.             if(DimensionInfo . MinRasterHeight <= Height && Height <= DimensionInfo . MaxRasterHeight)
  2331.                 DisplayClip . MaxY = DisplayClip . MinY + Height - 1;
  2332.  
  2333.             if(!ScreenWidth)
  2334.                 ScreenWidth = DisplayClip . MaxX - DisplayClip . MinX + 1;
  2335.  
  2336.             if(!ScreenHeight)
  2337.                 ScreenHeight = DisplayClip . MaxY - DisplayClip . MinY + 1;
  2338.  
  2339.             MaxDepth = DimensionInfo . MaxDepth;
  2340.         }
  2341.         else
  2342.         {
  2343.             ScreenWidth = ScreenHeight = 0;
  2344.             MaxDepth = 4;
  2345.         }
  2346.  
  2347.             /* We'll configure the screen parameters at
  2348.              * run time, at first we'll set up the screen
  2349.              * depth.
  2350.              */
  2351.  
  2352. PenReset:    if(!Config -> ScreenConfig -> UsePens && Kick30)
  2353.         {
  2354.             for(i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  2355.                 PenArray[i] = Config -> ScreenConfig -> PenArray[i];
  2356.  
  2357.             PenArray[i] = (UWORD)~0;
  2358.         }
  2359.         else
  2360.         {
  2361.             UWORD *Data;
  2362.  
  2363.             switch(Config -> ScreenConfig -> ColourMode)
  2364.             {
  2365.                 case COLOUR_EIGHT:
  2366.  
  2367.                     Data = ANSIPens;
  2368.                     break;
  2369.  
  2370.                 case COLOUR_SIXTEEN:
  2371.  
  2372.                     Data = EGAPens;
  2373.                     break;
  2374.  
  2375.                 case COLOUR_AMIGA:
  2376.  
  2377.                     Data = StandardPens;
  2378.                     break;
  2379.  
  2380.                 default:
  2381.  
  2382.                     Data = NULL;
  2383.                     break;
  2384.             }
  2385.  
  2386.             if(Data)
  2387.             {
  2388.                 for(i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  2389.                     PenArray[i] = Data[i];
  2390.  
  2391.                 PenArray[i] = (UWORD)~0;
  2392.             }
  2393.         }
  2394.  
  2395.         switch(Config -> ScreenConfig -> ColourMode)
  2396.         {
  2397.             case COLOUR_EIGHT:
  2398.  
  2399.                     // Special screen depth requested?
  2400.  
  2401.                 if(Config -> ScreenConfig -> Depth)
  2402.                 {
  2403.                         // The minimum number of colours required
  2404.  
  2405.                     if(Config -> ScreenConfig -> Blinking)
  2406.                         ScreenDepth = 4;
  2407.                     else
  2408.                         ScreenDepth = 3;
  2409.  
  2410.                         // This is what the user wanted
  2411.  
  2412.                     RealDepth = Config -> ScreenConfig -> Depth;
  2413.  
  2414.                         // Too deep for this display mode?
  2415.  
  2416.                     if(RealDepth > MaxDepth)
  2417.                         RealDepth = MaxDepth;
  2418.  
  2419.                         // Less colours than required?
  2420.  
  2421.                     if(RealDepth < ScreenDepth && ScreenDepth <= MaxDepth)
  2422.                         RealDepth = ScreenDepth;
  2423.  
  2424.                         // Not enough colours to display it?
  2425.  
  2426.                     if(RealDepth < ScreenDepth)
  2427.                     {
  2428.                             // Return to standard mode
  2429.  
  2430.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2431.  
  2432.                         ConfigChanged = TRUE;
  2433.  
  2434.                         goto PenReset;
  2435.                     }
  2436.                 }
  2437.                 else
  2438.                 {
  2439.                         // The minimum number of colours
  2440.  
  2441.                     if(Config -> ScreenConfig -> Blinking)
  2442.                         ScreenDepth = 4;
  2443.                     else
  2444.                         ScreenDepth = 3;
  2445.  
  2446.                         // Too many for this mode?
  2447.  
  2448.                     if(ScreenDepth > MaxDepth)
  2449.                     {
  2450.                             // Return to standard mode
  2451.  
  2452.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2453.  
  2454.                         ConfigChanged = TRUE;
  2455.  
  2456.                         goto PenReset;
  2457.                     }
  2458.  
  2459.                     RealDepth = ScreenDepth;
  2460.                 }
  2461.  
  2462.                 TagArray[Count++] = SA_Pens;
  2463.                 TagArray[Count++] = (LONG)PenArray;
  2464.  
  2465.                 TagArray[Count++] = SA_BlockPen;
  2466.                 TagArray[Count++] = PenArray[SHADOWPEN];
  2467.  
  2468.                 TagArray[Count++] = SA_DetailPen;
  2469.                 TagArray[Count++] = PenArray[BACKGROUNDPEN];
  2470.  
  2471.                 break;
  2472.  
  2473.             case COLOUR_SIXTEEN:
  2474.  
  2475.                 if(Config -> ScreenConfig -> Depth)
  2476.                 {
  2477.                     if(Config -> ScreenConfig -> Blinking && MaxDepth > 4)
  2478.                         ScreenDepth = 5;
  2479.                     else
  2480.                         ScreenDepth = 4;
  2481.  
  2482.                     RealDepth = Config -> ScreenConfig -> Depth;
  2483.  
  2484.                     if(RealDepth > MaxDepth)
  2485.                         RealDepth = MaxDepth;
  2486.  
  2487.                     if(RealDepth < ScreenDepth && ScreenDepth <= MaxDepth)
  2488.                         RealDepth = ScreenDepth;
  2489.  
  2490.                     if(RealDepth < ScreenDepth)
  2491.                     {
  2492.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2493.  
  2494.                         ConfigChanged = TRUE;
  2495.  
  2496.                         goto PenReset;
  2497.                     }
  2498.                 }
  2499.                 else
  2500.                 {
  2501.                     if(Config -> ScreenConfig -> Blinking && MaxDepth > 4)
  2502.                         ScreenDepth = 5;
  2503.                     else
  2504.                         ScreenDepth = 4;
  2505.  
  2506.                     if(ScreenDepth > MaxDepth)
  2507.                     {
  2508.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2509.  
  2510.                         ConfigChanged = TRUE;
  2511.  
  2512.                         goto PenReset;
  2513.                     }
  2514.  
  2515.                     RealDepth = ScreenDepth;
  2516.                 }
  2517.  
  2518.                 TagArray[Count++] = SA_Pens;
  2519.                 TagArray[Count++] = (LONG)PenArray;
  2520.  
  2521.                 TagArray[Count++] = SA_BlockPen;
  2522.                 TagArray[Count++] = PenArray[SHADOWPEN];
  2523.  
  2524.                 TagArray[Count++] = SA_DetailPen;
  2525.                 TagArray[Count++] = PenArray[BACKGROUNDPEN];
  2526.  
  2527.                 break;
  2528.  
  2529.             case COLOUR_MONO:
  2530.  
  2531.                 if(Config -> ScreenConfig -> Depth)
  2532.                     RealDepth = Config -> ScreenConfig -> Depth;
  2533.                 else
  2534.                     RealDepth = 1;
  2535.  
  2536.                 if(RealDepth > MaxDepth)
  2537.                     RealDepth = MaxDepth;
  2538.  
  2539.                 break;
  2540.  
  2541.             case COLOUR_AMIGA:
  2542.  
  2543.                 if(Config -> ScreenConfig -> Depth)
  2544.                     RealDepth = Config -> ScreenConfig -> Depth;
  2545.                 else
  2546.                     RealDepth = 2;
  2547.  
  2548.                 if(RealDepth > MaxDepth)
  2549.                     RealDepth = MaxDepth;
  2550.  
  2551.                 TagArray[Count++] = SA_Pens;
  2552.                 TagArray[Count++] = (LONG)PenArray;
  2553.  
  2554.                 break;
  2555.         }
  2556.  
  2557.             /* Add the depth value. */
  2558.  
  2559.         TagArray[Count++] = SA_Depth;
  2560.         TagArray[Count++] = RealDepth;
  2561.  
  2562.             /* Terminate the tag array. */
  2563.  
  2564.         TagArray[Count] = TAG_END;
  2565.  
  2566.             /* Set the plane mask. */
  2567.  
  2568.         DepthMask = (1L << RealDepth) - 1;
  2569.  
  2570.             /* Inquire overscan limits and try to create an interleaved
  2571.              * bitmap if possible.
  2572.              */
  2573.  
  2574.         if(Config -> ScreenConfig -> FasterLayout && RealDepth > 1 && !Kick30)
  2575.             InterleavedBitMap = CreateInterleavedBitMap(DisplayClip . MaxX - DisplayClip . MinX + 1,DisplayClip . MaxY - DisplayClip . MinY + 1,RealDepth);
  2576.         else
  2577.             InterleavedBitMap = NULL;
  2578.  
  2579. #ifdef _M68030
  2580. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'030 ",TermDate,TermIDString);
  2581. #else
  2582. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"",TermDate,TermIDString);
  2583. #endif    /* _M68030 */
  2584.  
  2585.         if(InterleavedBitMap)
  2586.         {
  2587.             if(Screen = (struct Screen *)OpenScreenTags(NULL,
  2588.                 ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  2589.                 ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  2590.  
  2591.                 SA_Title,    ScreenTitle,
  2592.                 SA_DClip,    &DisplayClip,
  2593.                 SA_BitMap,    InterleavedBitMap,
  2594.                 SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  2595.                 SA_Font,    &UserFont,
  2596.                 SA_Behind,    TRUE,
  2597.                 SA_AutoScroll,    TRUE,
  2598.                 SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  2599.                 SA_PubName,    TermIDString,
  2600.                 SA_ErrorCode,    &ErrorCode,
  2601.                 SA_BackFill,    &BackfillHook,
  2602.                 TAG_MORE,    TagArray,
  2603.             TAG_END))
  2604.                 UseMasking = FALSE;
  2605.         }
  2606.         else
  2607.         {
  2608.             BYTE Interleaved;
  2609.  
  2610.             if(Config -> ScreenConfig -> FasterLayout && Kick30 && RealDepth > 1)
  2611.                 Interleaved = TRUE;
  2612.             else
  2613.                 Interleaved = FALSE;
  2614.  
  2615.             if(Screen = (struct Screen *)OpenScreenTags(NULL,
  2616.                 ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  2617.                 ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  2618.  
  2619.                 SA_Title,    ScreenTitle,
  2620.                 SA_DClip,    &DisplayClip,
  2621.                 SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  2622.                 SA_Font,    &UserFont,
  2623.                 SA_Behind,    TRUE,
  2624.                 SA_AutoScroll,    TRUE,
  2625.                 SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  2626.                 SA_PubName,    TermIDString,
  2627.                 SA_ErrorCode,    &ErrorCode,
  2628.                 SA_Interleaved,    Interleaved,
  2629.                 SA_BackFill,    &BackfillHook,
  2630.                 TAG_MORE,    TagArray,
  2631.             TAG_END))
  2632.             {
  2633.                 if(Interleaved)
  2634.                     UseMasking = FALSE;
  2635.                 else
  2636.                     UseMasking = TRUE;
  2637.             }
  2638.         }
  2639.  
  2640.             /* We've got an error. */
  2641.  
  2642.         if(!Screen)
  2643.         {
  2644.             if(!OpenFailed)
  2645.             {
  2646.                 struct Screen *PubScreen;
  2647.  
  2648.                 switch(ErrorCode)
  2649.                 {
  2650.                         /* Can't open screen with these display
  2651.                          * modes.
  2652.                          */
  2653.  
  2654.                     case OSERR_NOMONITOR:
  2655.                     case OSERR_NOCHIPS:
  2656.                     case OSERR_UNKNOWNMODE:
  2657.                     case OSERR_NOTAVAILABLE:
  2658.  
  2659.                         if(PubScreen = LockPubScreen(NULL))
  2660.                         {
  2661.                             Config -> ScreenConfig -> DisplayMode = GetVPModeID(&PubScreen -> ViewPort);
  2662.  
  2663.                             UnlockPubScreen(NULL,PubScreen);
  2664.                         }
  2665.                         else
  2666.                             Config -> ScreenConfig -> DisplayMode = HIRES_KEY;
  2667.  
  2668.                         OpenFailed = TRUE;
  2669.  
  2670.                         goto OpenS;
  2671.  
  2672.                     case OSERR_PUBNOTUNIQUE:
  2673.  
  2674.                         return(LocaleString(MSG_TERMINIT_SCREEN_ID_ALREADY_IN_USE_TXT));
  2675.                 }
  2676.             }
  2677.  
  2678.                 /* Some different error, probably out of
  2679.                  * memory.
  2680.                  */
  2681.  
  2682.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_SCREEN_TXT));
  2683.         }
  2684.  
  2685.         if(!(DrawInfo = GetScreenDrawInfo(Screen)))
  2686.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_SCREEN_DRAWINFO_TXT));
  2687.  
  2688.         CreateMenuGlyphs(Screen,DrawInfo,&AmigaGlyph,&CheckGlyph);
  2689.  
  2690.         VPort = &Screen -> ViewPort;
  2691.  
  2692.         ScreenWidth    = Screen -> Width;
  2693.         ScreenHeight    = Screen -> Height;
  2694.  
  2695.         StatusSizeSetup(Screen,&StatusWidth,&StatusHeight);
  2696.  
  2697.             /* Obtain visual info (whatever that may be). */
  2698.  
  2699.         if(!(VisualInfo = GetVisualInfo(Screen,TAG_DONE)))
  2700.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  2701.  
  2702.         if(Config -> ScreenConfig -> TitleBar)
  2703.         {
  2704.             Top = Screen -> BarHeight + 1;
  2705.  
  2706.             Height = Screen -> Height - (Screen -> BarHeight + 1 + StatusHeight);
  2707.         }
  2708.         else
  2709.         {
  2710.             Top = 0;
  2711.  
  2712.             Height = Screen -> Height - StatusHeight;
  2713.         }
  2714.  
  2715.             /* Open the main window. */
  2716.  
  2717.         if(!(Window = OpenWindowTags(NULL,
  2718.             WA_Top,        Top,
  2719.             WA_Left,    0,
  2720.             WA_Width,    Screen -> Width,
  2721.             WA_Height,    Height,
  2722.             WA_Backdrop,    TRUE,
  2723.             WA_Borderless,    TRUE,
  2724.             WA_SmartRefresh,TRUE,
  2725.             WA_CustomScreen,Screen,
  2726.             WA_NewLookMenus,TRUE,
  2727.             WA_RMBTrap,    TRUE,
  2728.             WA_IDCMP,    IDCMP_RAWKEY | IDCMP_INACTIVEWINDOW | IDCMP_ACTIVEWINDOW | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_SIZEVERIFY | IDCMP_IDCMPUPDATE,
  2729.  
  2730.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  2731.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  2732.         TAG_DONE)))
  2733.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2734.     }
  2735.  
  2736.         /* Fill the `default' colour with current values. */
  2737.  
  2738.     if(!Config -> ScreenConfig -> UseWorkbench && Initializing && !SharedScreen)
  2739.     {
  2740.         for(i = 0 ; i < 16 ; i++)
  2741.             DefaultColours[i] = GetRGB4(VPort -> ColorMap,i);
  2742.  
  2743.         Initializing = FALSE;
  2744.     }
  2745.  
  2746.         /* Load the approriate colours. */
  2747.  
  2748.     if(LoadColours)
  2749.     {
  2750.         switch(Config -> ScreenConfig -> ColourMode)
  2751.         {
  2752.             case COLOUR_EIGHT:
  2753.  
  2754.                 CopyMem(ANSIColours,Config -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  2755.                 break;
  2756.  
  2757.             case COLOUR_SIXTEEN:
  2758.  
  2759.                 CopyMem(EGAColours,Config -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  2760.                 break;
  2761.  
  2762.             case COLOUR_AMIGA:
  2763.  
  2764.                 CopyMem(DefaultColours,Config -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  2765.                 break;
  2766.  
  2767.             case COLOUR_MONO:
  2768.  
  2769.                 CopyMem(AtomicColours,Config -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  2770.                 break;
  2771.         }
  2772.  
  2773.         LoadColours = FALSE;
  2774.     }
  2775.  
  2776.         /* Reset the current colours and the blinking equivalents. */
  2777.  
  2778.     PaletteSetup(Config);
  2779.  
  2780.     if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  2781.         LoadRGB4(VPort,NormalColours,PaletteSize);
  2782.  
  2783.         /* Get the vanilla rendering pens. */
  2784.  
  2785.     RenderPens[0] = DrawInfo -> dri_Pens[BACKGROUNDPEN];
  2786.     RenderPens[1] = DrawInfo -> dri_Pens[TEXTPEN];
  2787.     RenderPens[2] = DrawInfo -> dri_Pens[SHINEPEN];
  2788.     RenderPens[3] = DrawInfo -> dri_Pens[FILLPEN];
  2789.  
  2790.         /* Are we to use the Workbench screen for text output? */
  2791.  
  2792.     if(Config -> ScreenConfig -> UseWorkbench || (SharedScreen && Kick30))
  2793.     {
  2794.         if(Kick30 && (Config -> ScreenConfig -> ColourMode == COLOUR_EIGHT || Config -> ScreenConfig -> ColourMode == COLOUR_SIXTEEN))
  2795.         {
  2796.             ULONG    R,G,B;
  2797.             BYTE    GotAll = TRUE;
  2798.             WORD    NumPens;
  2799.  
  2800.             if(Config -> ScreenConfig -> ColourMode == COLOUR_EIGHT)
  2801.                 NumPens = 8;
  2802.             else
  2803.                 NumPens = 16;
  2804.  
  2805.             for(i = 0 ; i < 16 ; i++)
  2806.                 MappedPens[1][i] = FALSE;
  2807.  
  2808.                 /* Allocate the text rendering pens, note that
  2809.                  * we will use the currently installed palette
  2810.                  * to obtain those pens which match them best.
  2811.                  * The user will be unable to change these
  2812.                  * colours.
  2813.                  */
  2814.  
  2815.             for(i = 0 ; i < NumPens ; i++)
  2816.             {
  2817.                     /* Split the 12 bit colour palette entry. */
  2818.  
  2819.                 R = (NormalColours[i] >> 8) & 0xF;
  2820.                 G = (NormalColours[i] >> 4) & 0xF;
  2821.                 B =  NormalColours[i]       & 0xF;
  2822.  
  2823.                     /* Try to obtain a matching pen. */
  2824.  
  2825.                 if((MappedPens[0][i] = ObtainBestPen(VPort -> ColorMap,SPREAD((R << 4) | R),SPREAD((G << 4) | G),SPREAD((B << 4) | B),
  2826.                     OBP_FailIfBad,TRUE,
  2827.                 TAG_DONE)) == -1)
  2828.                 {
  2829.                     MappedPens[1][i] = FALSE;
  2830.  
  2831.                     GotAll = FALSE;
  2832.  
  2833.                     break;
  2834.                 }
  2835.                 else
  2836.                     MappedPens[1][i] = TRUE;
  2837.             }
  2838.  
  2839.                 /* Did we get what we wanted? */
  2840.  
  2841.             if(!GotAll)
  2842.             {
  2843.                     /* Release all the pens we succeeded
  2844.                      * in allocating.
  2845.                      */
  2846.  
  2847.                 for(i = 0 ; i < NumPens ; i++)
  2848.                 {
  2849.                     if(MappedPens[1][i])
  2850.                         ReleasePen(VPort -> ColorMap,MappedPens[0][i]);
  2851.                 }
  2852.  
  2853.                     /* Use the default rendering pens. */
  2854.  
  2855.                 for(i = 0 ; i < 4 ; i++)
  2856.                 {
  2857.                     MappedPens[0][i] = RenderPens[i];
  2858.                     MappedPens[1][i] = FALSE;
  2859.                 }
  2860.  
  2861.                     /* Set the remaining pens to defaults. */
  2862.  
  2863.                 for(i = 4 ; i < NumPens ; i++)
  2864.                 {
  2865.                     MappedPens[0][i] = RenderPens[1];
  2866.                     MappedPens[1][i] = FALSE;
  2867.                 }
  2868.             }
  2869.             else
  2870.                 AllocatedPens = TRUE;
  2871.         }
  2872.         else
  2873.         {
  2874.                 /* Use the default rendering pens. */
  2875.  
  2876.             if(Config -> ScreenConfig -> ColourMode == COLOUR_AMIGA)
  2877.             {
  2878.                 for(i = 0 ; i < 4 ; i++)
  2879.                 {
  2880.                     MappedPens[0][i] = RenderPens[i];
  2881.                     MappedPens[1][i] = FALSE;
  2882.                 }
  2883.  
  2884.                     /* Set the remaining pens to defaults. */
  2885.  
  2886.                 for(i = 4 ; i < 16 ; i++)
  2887.                 {
  2888.                     MappedPens[0][i] = RenderPens[1];
  2889.                     MappedPens[1][i] = FALSE;
  2890.                 }
  2891.             }
  2892.             else
  2893.             {
  2894.                 for(i = 0 ; i < 16 ; i++)
  2895.                 {
  2896.                     MappedPens[0][i] = RenderPens[i & 1];
  2897.                     MappedPens[1][i] = FALSE;
  2898.                 }
  2899.             }
  2900.         }
  2901.  
  2902.         for(i = 0 ; i < 16 ; i++)
  2903.         {
  2904.             MappedPens[0][i + 16] = MappedPens[0][i];
  2905.             MappedPens[1][i + 16] = FALSE;
  2906.         }
  2907.     }
  2908.     else
  2909.     {
  2910.             /* Reset the colour translation table. */
  2911.  
  2912.         for(i = 0 ; i < 32 ; i++)
  2913.         {
  2914.             MappedPens[0][i] = i;
  2915.             MappedPens[1][i] = FALSE;
  2916.         }
  2917.     }
  2918.  
  2919.         /* Determine default text rendering colour. */
  2920.  
  2921.     switch(Config -> ScreenConfig -> ColourMode)
  2922.     {
  2923.         case COLOUR_SIXTEEN:
  2924.  
  2925.             SafeTextPen = MappedPens[0][15];
  2926.             break;
  2927.  
  2928.         case COLOUR_EIGHT:
  2929.  
  2930.             SafeTextPen = MappedPens[0][7];
  2931.             break;
  2932.  
  2933.         case COLOUR_AMIGA:
  2934.         case COLOUR_MONO:
  2935.  
  2936.             SafeTextPen = MappedPens[0][1];
  2937.             break;
  2938.     }
  2939.  
  2940.         /* Determine window inner dimensions and top/left edge offsets. */
  2941.  
  2942.     WindowLeft    = Window -> BorderLeft;
  2943.     WindowTop    = Window -> BorderTop;
  2944.  
  2945.     WindowWidth    = Window -> Width - (Window -> BorderLeft + Window -> BorderRight);
  2946.     WindowHeight    = Window -> Height - (Window -> BorderTop + Window -> BorderBottom);
  2947.  
  2948.         /* Set up scaling data (bitmaps & rastports). */
  2949.  
  2950.     if(!CreateScale())
  2951.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_FONT_SCALING_INFO_TXT));
  2952.  
  2953.     if(!CreateOffsetTables())
  2954.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_OFFSET_TABLES_TXT));
  2955.  
  2956.     TabStopMax = Window -> WScreen -> Width / TextFontWidth;
  2957.  
  2958.         /* Allocate the tab stop line. */
  2959.  
  2960.     if(!(TabStops = (BYTE *)AllocVecPooled(TabStopMax,MEMF_ANY | MEMF_CLEAR)))
  2961.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  2962.  
  2963.         /* Push it on the window stack (should become bottommost
  2964.          * entry).
  2965.          */
  2966.  
  2967.     PushWindow(Window);
  2968.  
  2969.     if(TermPort)
  2970.         TermPort -> TopWindow = Window;
  2971.  
  2972.     StatusWindow = NULL;
  2973.  
  2974.     if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  2975.     {
  2976.         if(Config -> ScreenConfig -> SplitStatus)
  2977.         {
  2978.             if(!(StatusWindow = OpenWindowTags(NULL,
  2979.                 WA_Top,            Window -> TopEdge + Window -> Height,
  2980.                 WA_Left,        Window -> LeftEdge,
  2981.                 WA_InnerWidth,        StatusWidth,
  2982.                 WA_InnerHeight,        StatusHeight,
  2983.                 WA_GimmeZeroZero,    TRUE,
  2984.                 WA_DragBar,        TRUE,
  2985.                 WA_DepthGadget,        TRUE,
  2986.                 WA_NewLookMenus,    TRUE,
  2987.                 WA_Title,        ScreenTitle,
  2988.                 WA_CustomScreen,    Window -> WScreen,
  2989.                 WA_RMBTrap,        TRUE,
  2990.                 WA_CloseGadget,        TRUE,
  2991.  
  2992.                 AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  2993.                 CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  2994.             TAG_DONE)))
  2995.                 return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_STATUS_WINDOW_TXT));
  2996.         }
  2997.         else
  2998.         {
  2999.             if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  3000.             {
  3001.                 if(!(StatusWindow = OpenWindowTags(NULL,
  3002.                     WA_Top,        Window -> TopEdge + Window -> Height,
  3003.                     WA_Left,    0,
  3004.                     WA_Width,    Screen -> Width,
  3005.                     WA_Height,    Screen -> Height - (Window -> TopEdge + Window -> Height),
  3006.                     WA_Backdrop,    TRUE,
  3007.                     WA_Borderless,    TRUE,
  3008.                     WA_SmartRefresh,TRUE,
  3009.                     WA_NewLookMenus,TRUE,
  3010.                     WA_CustomScreen,Screen,
  3011.                     WA_RMBTrap,    TRUE,
  3012.  
  3013.                     AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  3014.                     CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  3015.                 TAG_DONE)))
  3016.                     return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_STATUS_WINDOW_TXT));
  3017.             }
  3018.         }
  3019.     }
  3020.  
  3021.     if(StatusWindow)
  3022.     {
  3023.         StatusWindow -> UserPort = Window -> UserPort;
  3024.  
  3025.         ModifyIDCMP(StatusWindow,Window -> IDCMPFlags);
  3026.     }
  3027.  
  3028.     RPort = Window -> RPort;
  3029.  
  3030.         /* Default console setup. */
  3031.  
  3032.     CursorX = 0;
  3033.     CursorY    = 0;
  3034.  
  3035.     SetDrMd(RPort,JAM2);
  3036.  
  3037.         /* Set the font. */
  3038.  
  3039.     SetFont(RPort,CurrentFont);
  3040.  
  3041.         /* Redirect AmigaDOS requesters. */
  3042.  
  3043.     OldWindowPtr = ThisProcess -> pr_WindowPtr;
  3044.  
  3045.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  3046.  
  3047.         /* Create the character raster. */
  3048.  
  3049.     if(!CreateRaster())
  3050.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_SCREEN_RASTER_TXT));
  3051.  
  3052.     ConOutputUpdate();
  3053.  
  3054.     ConFontScaleUpdate();
  3055.  
  3056.         /* Set up the scrolling info. */
  3057.  
  3058.     ScrollLineCount = Window -> WScreen -> Height / TextFontHeight;
  3059.  
  3060.     if(!(ScrollLines = (struct ScrollLineInfo *)AllocVecPooled(sizeof(struct ScrollLineInfo) * ScrollLineCount,MEMF_ANY|MEMF_CLEAR)))
  3061.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SCROLLING_SUPPORT_INFO_TXT));
  3062.  
  3063.         /* Create the menu strip. */
  3064.  
  3065.     if(Error = BuildMenu())
  3066.         return(Error);
  3067.  
  3068.         /* Disable the `Execute ARexx Command' menu item if
  3069.          * the rexx server is not available.
  3070.          */
  3071.  
  3072.     if(!RexxSysBase)
  3073.         OffItem(MEN_EXECUTE_REXX_COMMAND);
  3074.  
  3075.     if(Recording)
  3076.     {
  3077.         OnItem(MEN_RECORD_LINE);
  3078.  
  3079.         CheckItem(MEN_RECORD,TRUE);
  3080.         CheckItem(MEN_RECORD_LINE,RecordingLine);
  3081.     }
  3082.     else
  3083.     {
  3084.         OffItem(MEN_RECORD_LINE);
  3085.  
  3086.         CheckItem(MEN_RECORD,FALSE);
  3087.         CheckItem(MEN_RECORD_LINE,FALSE);
  3088.     }
  3089.  
  3090.     CheckItem(MEN_DISABLE_TRAPS,!(WatchTraps && GenericListTable[GLIST_TRAP] -> ListHeader . mlh_Head -> mln_Succ));
  3091.  
  3092.     if(StatusWindow)
  3093.     {
  3094.         SetMenuStrip(StatusWindow,Menu);
  3095.  
  3096.         StatusWindow -> Flags &= ~WFLG_RMBTRAP;
  3097.  
  3098.         SetDrMd(StatusWindow -> RPort,JAM2);
  3099.     }
  3100.  
  3101.         /* Add a tick if file capture is active. */
  3102.  
  3103.     if(FileCapture)
  3104.         CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  3105.     else
  3106.         CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  3107.  
  3108.         /* Add a tick if printer capture is active. */
  3109.  
  3110.     CheckItem(MEN_CAPTURE_TO_PRINTER,PrinterCapture);
  3111.  
  3112.         /* Add a tick if the buffer is frozen. */
  3113.  
  3114.     CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  3115.  
  3116.         /* Disable the dialing functions if online. */
  3117.  
  3118.     if(Online)
  3119.         SetDialMenu(FALSE);
  3120.     else
  3121.         SetDialMenu(TRUE);
  3122.  
  3123.         /* Update the clipboard menus. */
  3124.  
  3125.     SetClipMenu(FALSE);
  3126.  
  3127.     if(!XProtocolBase)
  3128.         SetTransferMenu(FALSE);
  3129.  
  3130.         /* Disable the `Print Screen' and `Save ASCII' functions
  3131.          * if raster is not enabled.
  3132.          */
  3133.  
  3134.     SetRasterMenu(RasterEnabled);
  3135.  
  3136.         /* Enable the menu. */
  3137.  
  3138.     Window -> Flags &= ~WFLG_RMBTRAP;
  3139.  
  3140.     strcpy(EmulationName,LocaleString(MSG_TERMXEM_NO_EMULATION_TXT));
  3141.  
  3142.         /* Create the status server. */
  3143.  
  3144.     Forbid();
  3145.  
  3146.     if(StatusProcess = CreateNewProcTags(
  3147.         NP_Entry,    StatusServer,
  3148.         NP_Name,    "term Status Process",
  3149.         NP_WindowPtr,    -1,
  3150.         NP_Priority,    5,
  3151.     TAG_DONE))
  3152.     {
  3153.         ClrSignal(SIG_HANDSHAKE);
  3154.  
  3155.         Wait(SIG_HANDSHAKE);
  3156.     }
  3157.  
  3158.     Permit();
  3159.  
  3160.         /* Status server has `died'. */
  3161.  
  3162.     if(!StatusProcess)
  3163.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_STATUS_TASK_TXT));
  3164.  
  3165.         /* Obtain the default public screen name just in case
  3166.          * we'll need it later.
  3167.          */
  3168.  
  3169.     GetDefaultPubScreen(DefaultPubScreenName);
  3170.  
  3171.         /* Set up the window size. */
  3172.  
  3173.     ScreenSizeStuff();
  3174.  
  3175.         /* Select the default console data processing routine. */
  3176.  
  3177.     Forbid();
  3178.  
  3179.     ConProcessData = ConProcessData8;
  3180.  
  3181.     Permit();
  3182.  
  3183.         /* Handle the remaining terminal setup. */
  3184.  
  3185.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  3186.     {
  3187.         if(!OpenEmulator(Config -> TerminalConfig -> EmulationFileName))
  3188.         {
  3189.             Config -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
  3190.  
  3191.             ResetDisplay = TRUE;
  3192.  
  3193.             RasterEnabled = TRUE;
  3194.  
  3195.             MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),Config -> TerminalConfig -> EmulationFileName);
  3196.         }
  3197.         else
  3198.         {
  3199.             if(RasterEnabled)
  3200.                 RasterEnabled = FALSE;
  3201.  
  3202.             SetRasterMenu(RasterEnabled);
  3203.         }
  3204.     }
  3205.  
  3206.         /* Choose the right console data processing routine. */
  3207.  
  3208.     ConProcessUpdate();
  3209.  
  3210.         /* Reset terminal emulation. */
  3211.  
  3212.     if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  3213.     {
  3214.         ClearCursor();
  3215.  
  3216.         Reset();
  3217.  
  3218.         DrawCursor();
  3219.     }
  3220.     else
  3221.     {
  3222.         if(XEmulatorBase)
  3223.             XEmulatorResetConsole(XEM_IO);
  3224.     }
  3225.  
  3226.         /* Restart the fast! macro panel. */
  3227.  
  3228.     if(HadFastMacros || Config -> MiscConfig -> OpenFastMacroPanel)
  3229.         OpenFastWindow();
  3230.  
  3231.     if(Config -> TerminalConfig -> UseTerminalTask && Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  3232.         CreateEmulationProcess();
  3233.     else
  3234.         DeleteEmulationProcess();
  3235.  
  3236.     return(NULL);
  3237. }
  3238.  
  3239.     /* CloseAll():
  3240.      *
  3241.      *    Free all resources and leave the program.
  3242.      */
  3243.  
  3244. VOID __regargs
  3245. CloseAll(BYTE CloseDOS)
  3246. {
  3247.     WORD i;
  3248.  
  3249.     Forbid();
  3250.  
  3251.     if(RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Name)
  3252.         RemSemaphore(&RendezvousSemaphore);
  3253.  
  3254.     Permit();
  3255.  
  3256. #ifdef DATAFEED
  3257.     {
  3258.         extern BPTR DataFeed;
  3259.  
  3260.         if(DataFeed)
  3261.         {
  3262.             Close(DataFeed);
  3263.  
  3264.             DataFeed = NULL;
  3265.         }
  3266.     }
  3267. #endif    /* DATAFEED */
  3268.  
  3269.     Forbid();
  3270.  
  3271.     if(DialMsg)
  3272.     {
  3273.         DialMsg -> rm_Result1 = RC_WARN;
  3274.         DialMsg -> rm_Result2 = 0;
  3275.  
  3276.         ReplyMsg(DialMsg);
  3277.  
  3278.         DialMsg = NULL;
  3279.     }
  3280.  
  3281.     Permit();
  3282.  
  3283.     DeleteRecord();
  3284.  
  3285.     DeleteQueueProcess();
  3286.  
  3287.     SoundExit();
  3288.  
  3289.     SZ_SizeCleanup();
  3290.  
  3291.     FreeDialList(TRUE);
  3292.  
  3293.     if(SpecialQueue)
  3294.     {
  3295.         DeleteMsgQueue(SpecialQueue);
  3296.  
  3297.         SpecialQueue = NULL;
  3298.     }
  3299.  
  3300.     if(SpecialTable)
  3301.     {
  3302.         FreeVecPooled(SpecialTable);
  3303.  
  3304.         SpecialTable = NULL;
  3305.     }
  3306.  
  3307.     if(AbortTable)
  3308.     {
  3309.         FreeVecPooled(AbortTable);
  3310.  
  3311.         AbortTable = NULL;
  3312.     }
  3313.  
  3314.     if(BackupConfig)
  3315.     {
  3316.         DeleteConfiguration(BackupConfig);
  3317.  
  3318.         BackupConfig = NULL;
  3319.     }
  3320.  
  3321.     if(IntuitionBase && Window)
  3322.         BlockWindows();
  3323.  
  3324.     /* ALWAYS */
  3325.     {
  3326.         extern struct MsgPort *RexxPort;
  3327.  
  3328.         if(RexxPort)
  3329.             RemPort(RexxPort);
  3330.     }
  3331.  
  3332.     if(EditList)
  3333.     {
  3334.         DeleteList(EditList);
  3335.  
  3336.         EditList = NULL;
  3337.     }
  3338.  
  3339.     if(EditLabels)
  3340.     {
  3341.         FreeVecPooled(EditLabels);
  3342.  
  3343.         EditLabels = NULL;
  3344.     }
  3345.  
  3346.     if(TermRexxPort)
  3347.     {
  3348.         if(RexxSysBase)
  3349.         {
  3350.             struct Message *Msg;
  3351.  
  3352.             while(Msg = GetMsg(TermRexxPort))
  3353.                 ReplyMsg(Msg);
  3354.         }
  3355.  
  3356.         DeleteMsgPort(TermRexxPort);
  3357.  
  3358.         TermRexxPort = NULL;
  3359.     }
  3360.  
  3361.     if(RexxProcess)
  3362.     {
  3363.         Forbid();
  3364.  
  3365.         Signal(RexxProcess,SIG_KILL);
  3366.  
  3367.         ClrSignal(SIG_HANDSHAKE);
  3368.  
  3369.         Wait(SIG_HANDSHAKE);
  3370.  
  3371.         Permit();
  3372.  
  3373.         RexxProcess = NULL;
  3374.     }
  3375.  
  3376.     if(RexxSysBase)
  3377.     {
  3378.         CloseLibrary(RexxSysBase);
  3379.  
  3380.         RexxSysBase = NULL;
  3381.     }
  3382.  
  3383.     if(XprIO && XProtocolBase)
  3384.         XProtocolCleanup(XprIO);
  3385.  
  3386.     if(XProtocolBase)
  3387.     {
  3388.         CloseLibrary(XProtocolBase);
  3389.  
  3390.         XProtocolBase = NULL;
  3391.     }
  3392.  
  3393.     if(XprIO)
  3394.     {
  3395.         FreeVec(XprIO);
  3396.  
  3397.         XprIO = NULL;
  3398.     }
  3399.  
  3400.     if(CursorKeys)
  3401.     {
  3402.         FreeVecPooled(CursorKeys);
  3403.  
  3404.         CursorKeys = NULL;
  3405.     }
  3406.  
  3407.     if(MacroKeys)
  3408.     {
  3409.         FreeVecPooled(MacroKeys);
  3410.  
  3411.         MacroKeys = NULL;
  3412.     }
  3413.  
  3414.     TerminateBuffer();
  3415.  
  3416.     DeleteSpeech();
  3417.  
  3418.     Forbid();
  3419.  
  3420.     BufferClosed = TRUE;
  3421.  
  3422.     DeleteBuffer();
  3423.  
  3424.     Permit();
  3425.  
  3426.     if(AttentionBuffers[0])
  3427.     {
  3428.         FreeVecPooled(AttentionBuffers[0]);
  3429.  
  3430.         AttentionBuffers[0] = NULL;
  3431.     }
  3432.  
  3433.     if(SendTable)
  3434.     {
  3435.         FreeTranslationTable(SendTable);
  3436.  
  3437.         SendTable = NULL;
  3438.     }
  3439.  
  3440.     if(ReceiveTable)
  3441.     {
  3442.         FreeTranslationTable(ReceiveTable);
  3443.  
  3444.         ReceiveTable = NULL;
  3445.     }
  3446.  
  3447.     FreeDialList(TRUE);
  3448.  
  3449.     DeleteOffsetTables();
  3450.  
  3451.     FreeList(&FastMacroList);
  3452.     FreeList((struct List *)&ReviewBufferHistory);
  3453.     FreeList((struct List *)&TextBufferHistory);
  3454.  
  3455.     for(i = GLIST_UPLOAD ; i < GLIST_COUNT ; i++)
  3456.     {
  3457.         if(GenericListTable[i])
  3458.         {
  3459.             DeleteGenericList(GenericListTable[i]);
  3460.  
  3461.             GenericListTable[i] = NULL;
  3462.         }
  3463.     }
  3464.  
  3465.     if(FileCapture)
  3466.     {
  3467.         BufferClose(FileCapture);
  3468.  
  3469.         if(!GetFileSize(CaptureName))
  3470.             DeleteFile(CaptureName);
  3471.         else
  3472.         {
  3473.             AddProtection(CaptureName,FIBF_EXECUTE);
  3474.  
  3475.             if(Config -> MiscConfig -> CreateIcons)
  3476.                 AddIcon(CaptureName,FILETYPE_TEXT,FALSE);
  3477.         }
  3478.  
  3479.         FileCapture = NULL;
  3480.     }
  3481.  
  3482.     if(PrinterCapture)
  3483.     {
  3484.         Close(PrinterCapture);
  3485.  
  3486.         PrinterCapture = NULL;
  3487.     }
  3488.  
  3489.         /* Close the external emulator. */
  3490.  
  3491.     if(XEmulatorBase)
  3492.     {
  3493.         if(XEM_IO)
  3494.         {
  3495.             XEmulatorMacroKeyFilter(XEM_IO,NULL);
  3496.             XEmulatorCloseConsole(XEM_IO);
  3497.             XEmulatorCleanup(XEM_IO);
  3498.  
  3499.             FreeVec(XEM_IO);
  3500.  
  3501.             XEM_IO = NULL;
  3502.         }
  3503.  
  3504.         CloseLibrary(XEmulatorBase);
  3505.  
  3506.         XEmulatorBase = NULL;
  3507.     }
  3508.  
  3509.     if(XEM_MacroKeys)
  3510.     {
  3511.         FreeVecPooled(XEM_MacroKeys);
  3512.  
  3513.         XEM_MacroKeys = NULL;
  3514.     }
  3515.  
  3516.     DeleteDisplay();
  3517.  
  3518.     if(KeySegment)
  3519.     {
  3520.         UnLoadSeg(KeySegment);
  3521.  
  3522.         KeySegment = NULL;
  3523.     }
  3524.  
  3525.     StopCall(TRUE);
  3526.  
  3527.     if(CheckBit != -1)
  3528.     {
  3529.         FreeSignal(CheckBit);
  3530.  
  3531.         CheckBit = -1;
  3532.     }
  3533.  
  3534.     ClearSerial();
  3535.  
  3536.     DeleteSerial();
  3537.  
  3538.     if(TimeRequest)
  3539.     {
  3540.         if(TimeRequest -> tr_node . io_Device)
  3541.             CloseDevice(TimeRequest);
  3542.  
  3543.         DeleteIORequest(TimeRequest);
  3544.  
  3545.         TimeRequest = NULL;
  3546.     }
  3547.  
  3548.     if(TimePort)
  3549.     {
  3550.         DeleteMsgPort(TimePort);
  3551.  
  3552.         TimePort = NULL;
  3553.     }
  3554.  
  3555.     ShutdownCx();
  3556.  
  3557.     if(TermPort)
  3558.     {
  3559.         if(TermID != -1)
  3560.         {
  3561.             ObtainSemaphore(&TermPort -> OpenSemaphore);
  3562.  
  3563.             TermPort -> OpenCount--;
  3564.  
  3565.             if(TermPort -> OpenCount <= 0 && !TermPort -> HoldIt)
  3566.             {
  3567.                 RemPort(&TermPort -> ExecNode);
  3568.  
  3569.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  3570.  
  3571.                 FreeVec(TermPort);
  3572.             }
  3573.             else
  3574.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  3575.  
  3576.             TermID = -1;
  3577.         }
  3578.  
  3579.         TermPort = NULL;
  3580.     }
  3581.  
  3582.     CloseClip();
  3583.  
  3584.     if(GTLayoutBase)
  3585.     {
  3586.         CloseLibrary(GTLayoutBase);
  3587.  
  3588.         GTLayoutBase = NULL;
  3589.     }
  3590.  
  3591.     if(Config)
  3592.     {
  3593.         DeleteConfiguration(Config);
  3594.  
  3595.         Config = NULL;
  3596.     }
  3597.  
  3598.     if(PrivateConfig)
  3599.     {
  3600.         DeleteConfiguration(PrivateConfig);
  3601.  
  3602.         PrivateConfig = NULL;
  3603.     }
  3604.  
  3605.     if(FakeInputEvent)
  3606.     {
  3607.         FreeVecPooled(FakeInputEvent);
  3608.  
  3609.         FakeInputEvent = NULL;
  3610.     }
  3611.  
  3612.     if(ConsoleDevice)
  3613.     {
  3614.         CloseDevice(ConsoleRequest);
  3615.  
  3616.         ConsoleDevice = NULL;
  3617.     }
  3618.  
  3619.     if(ConsoleRequest)
  3620.     {
  3621.         FreeVecPooled(ConsoleRequest);
  3622.  
  3623.         ConsoleRequest = NULL;
  3624.     }
  3625.  
  3626.     if(IconBase)
  3627.     {
  3628.         CloseLibrary(IconBase);
  3629.  
  3630.         IconBase = NULL;
  3631.     }
  3632.  
  3633.     if(DataTypesBase)
  3634.     {
  3635.         CloseLibrary(DataTypesBase);
  3636.  
  3637.         DataTypesBase = NULL;
  3638.     }
  3639.  
  3640.     if(WorkbenchBase)
  3641.     {
  3642.         CloseLibrary(WorkbenchBase);
  3643.  
  3644.         WorkbenchBase = NULL;
  3645.     }
  3646.  
  3647.     if(OwnDevUnitBase)
  3648.     {
  3649.         CloseLibrary(OwnDevUnitBase);
  3650.  
  3651.         OwnDevUnitBase = NULL;
  3652.     }
  3653.  
  3654.     if(CxBase)
  3655.     {
  3656.         CloseLibrary(CxBase);
  3657.  
  3658.         CxBase = NULL;
  3659.     }
  3660.  
  3661.     if(IFFParseBase)
  3662.     {
  3663.         CloseLibrary(IFFParseBase);
  3664.  
  3665.         IFFParseBase = NULL;
  3666.     }
  3667.  
  3668.     if(AslBase)
  3669.     {
  3670.         CloseLibrary(AslBase);
  3671.  
  3672.         AslBase = NULL;
  3673.     }
  3674.  
  3675.     if(DiskfontBase)
  3676.     {
  3677.         CloseLibrary(DiskfontBase);
  3678.  
  3679.         DiskfontBase = NULL;
  3680.     }
  3681.  
  3682.     if(GadToolsBase)
  3683.     {
  3684.         CloseLibrary(GadToolsBase);
  3685.  
  3686.         GadToolsBase = NULL;
  3687.     }
  3688.  
  3689.     if(LayersBase)
  3690.     {
  3691.         CloseLibrary(LayersBase);
  3692.  
  3693.         LayersBase = NULL;
  3694.     }
  3695.  
  3696.     if(GfxBase)
  3697.     {
  3698.         CloseLibrary(GfxBase);
  3699.  
  3700.         GfxBase = NULL;
  3701.     }
  3702.  
  3703.     if(IntuitionBase)
  3704.     {
  3705.         CloseLibrary(IntuitionBase);
  3706.  
  3707.         IntuitionBase = NULL;
  3708.     }
  3709.  
  3710.     LocaleClose();
  3711.  
  3712.     if(UtilityBase)
  3713.     {
  3714.         CloseLibrary(UtilityBase);
  3715.  
  3716.         UtilityBase = NULL;
  3717.     }
  3718.  
  3719. #ifdef DEBUG
  3720.     DebugExit();
  3721. #endif    /* DEBUG */
  3722.  
  3723. #ifdef BETA
  3724.     StopBetaTask();
  3725. #endif    /* BETA */
  3726.  
  3727.     MemoryCleanup();
  3728.  
  3729.     if(WBenchMsg)
  3730.     {
  3731.         CurrentDir(WBenchLock);
  3732.  
  3733.         if(DOSBase)
  3734.         {
  3735.             CloseLibrary(DOSBase);
  3736.  
  3737.             DOSBase = NULL;
  3738.         }
  3739.  
  3740.         Forbid();
  3741.  
  3742.         ReplyMsg((struct Message *)WBenchMsg);
  3743.  
  3744.         WBenchMsg = NULL;
  3745.     }
  3746.     else
  3747.     {
  3748.         if(CloseDOS && DOSBase)
  3749.         {
  3750.             CloseLibrary(DOSBase);
  3751.  
  3752.             DOSBase = NULL;
  3753.         }
  3754.     }
  3755. }
  3756.  
  3757.     /* OpenAll():
  3758.      *
  3759.      *    Open all required resources or return an error message
  3760.      *    if anything went wrong.
  3761.      */
  3762.  
  3763. STRPTR __regargs
  3764. OpenAll(STRPTR ConfigPath)
  3765. {
  3766.     extern    ULONG HookEntry(struct Hook *,APTR,APTR);
  3767.  
  3768.     UBYTE         PathBuffer[MAX_FILENAME_LENGTH];
  3769.     STRPTR         Result,Error,ConfigFileName = NULL;
  3770.     WORD         i;
  3771.     struct Node    *Node;
  3772.  
  3773.         /* Pretty cheap ;-) */
  3774.  
  3775.     Kick30 = (SysBase -> LibNode . lib_Version >= 39);
  3776.  
  3777.     if(!MemorySetup())
  3778.         return("Cannot create memory pool");
  3779.  
  3780. #ifdef DEBUG
  3781.     DebugInit();
  3782. #endif    /* DEBUG */
  3783.  
  3784.         /* Don't let it hit the ground! */
  3785.  
  3786.     ConTransfer = ConProcess;
  3787.  
  3788.         /* Remember the start of this session. */
  3789.  
  3790.     DateStamp(&SessionStart);
  3791.  
  3792.         /* Reset some flags. */
  3793.  
  3794.     BinaryTransfer    = TRUE;
  3795.  
  3796.     Status        = STATUS_READY;
  3797.     Online        = FALSE;
  3798.  
  3799.     InSequence    = FALSE;
  3800.     Quiet        = FALSE;
  3801.  
  3802.     TagDPI[0] . ti_Tag = TAG_DONE;
  3803.  
  3804.         /* Double buffered file locking. */
  3805.  
  3806.     NewList(&DoubleBufferList);
  3807.  
  3808.     InitSemaphore(&DoubleBufferSemaphore);
  3809.  
  3810.         /* Terminal emulation data. */
  3811.  
  3812.     InitSemaphore(&TerminalSemaphore);
  3813.  
  3814.         /* Text buffer task access semaphore. */
  3815.  
  3816.     InitSemaphore(&BufferTaskSemaphore);
  3817.  
  3818.         /* Set up all the lists. */
  3819.  
  3820.     NewList(&PacketHistoryList);
  3821.     NewList(&EmptyList);
  3822.     NewList(&FastMacroList);
  3823.     NewList(&TransferInfoList);
  3824.  
  3825.     NewList((struct List *)&ReviewBufferHistory);
  3826.     NewList((struct List *)&TextBufferHistory);
  3827.  
  3828.         /* Rendezvous setup. */
  3829.  
  3830.     InitSemaphore(&RendezvousSemaphore);
  3831.  
  3832.     RendezvousSemaphore . rs_Login        = RendezvousLogin;
  3833.     RendezvousSemaphore . rs_Logoff        = RendezvousLogoff;
  3834.     RendezvousSemaphore . rs_NewNode    = RendezvousNewNode;
  3835.  
  3836.         /* Open the translation tables. */
  3837.  
  3838.     LocaleOpen("term.catalog","english",20);
  3839.  
  3840.         /* Fill in the menu configuration. */
  3841.  
  3842.     LocalizeMenu(TermMenu,MSG_TERMDATA_PROJECT_MEN);
  3843.  
  3844.         /* Open intuition.library, any version. */
  3845.  
  3846.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  3847.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_INTUITION_LIBRARY_TXT));
  3848.  
  3849.     Forbid();
  3850.  
  3851.         /* Query the current public screen modes. */
  3852.  
  3853.     PublicModes = SetPubScreenModes(NULL);
  3854.  
  3855.         /* Set them back. */
  3856.  
  3857.     SetPubScreenModes(PublicModes);
  3858.  
  3859.     Permit();
  3860.  
  3861.         /* Open some more libraries. */
  3862.  
  3863.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  3864.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GRAPHICS_LIBRARY_TXT));
  3865.  
  3866.     if(!(LayersBase = OpenLibrary("layers.library",0)))
  3867.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_LAYERS_LIBRARY_TXT));
  3868.  
  3869.         /* Install the correct routines to query
  3870.          * the rendering colours and drawing mode.
  3871.          */
  3872.  
  3873.     if(!Kick30)
  3874.     {
  3875.         ReadAPen = OldGetAPen;
  3876.         ReadBPen = OldGetBPen;
  3877.         ReadDrMd = OldGetDrMd;
  3878.         SetWrMsk = OldSetWrMsk;
  3879.     }
  3880.     else
  3881.     {
  3882.         ReadAPen = NewGetAPen;
  3883.         ReadBPen = NewGetBPen;
  3884.         ReadDrMd = NewGetDrMd;
  3885.         SetWrMsk = NewSetWrMsk;
  3886.     }
  3887.  
  3888.     if(!(UtilityBase = OpenLibrary("utility.library",0)))
  3889.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_UTILITY_LIBRARY_TXT));
  3890.  
  3891.         /* Check if locale.library has already installed the operating system
  3892.          * patches required for localization.
  3893.          */
  3894.  
  3895.     LanguageCheck();
  3896.  
  3897.         /* Open the remaining libraries. */
  3898.  
  3899.     if(!(GadToolsBase = OpenLibrary("gadtools.library",0)))
  3900.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GADTOOLS_LIBRARY_TXT));
  3901.  
  3902.     if(!(AslBase = OpenLibrary("asl.library",0)))
  3903.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_ASL_LIBRARY_TXT));
  3904.  
  3905.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  3906.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_IFFPARSE_LIBRARY_TXT));
  3907.  
  3908.     if(!(CxBase = OpenLibrary("commodities.library",0)))
  3909.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_COMMODITIES_LIBRARY_TXT));
  3910.  
  3911.     if(!(DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",0)))
  3912.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_DISKFONT_LIBRARY_TXT));
  3913.  
  3914.         /* User interface. */
  3915.  
  3916.     if(!(GTLayoutBase = OpenLibrary("PROGDIR:gtlayout.library",0)))
  3917.     {
  3918.         if(!(GTLayoutBase = OpenLibrary("gtlayout.library",0)))
  3919.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GTLAYOUT_LIBRARY_TXT));
  3920.     }
  3921.  
  3922.         /* Open OwnDevUnit.library, don't complain if it fails. */
  3923.  
  3924.     OwnDevUnitBase = OpenLibrary(ODU_NAME,0);
  3925.  
  3926.         /* Open workbench.library, don't complain if it fails. */
  3927.  
  3928.     WorkbenchBase = OpenLibrary("workbench.library",0);
  3929.  
  3930.         /* Open icon.library as well, don't complain if it fails either. */
  3931.  
  3932.     IconBase = OpenLibrary("icon.library",0);
  3933.  
  3934.         /* Try to open datatypes.library, just for the fun of it. */
  3935.  
  3936.     DataTypesBase = OpenLibrary("datatypes.library",39);
  3937.  
  3938.     if(!(ConsoleRequest = (struct IOStdReq *)AllocVecPooled(sizeof(struct IOStdReq),MEMF_ANY|MEMF_CLEAR)))
  3939.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CONSOLE_REQUEST_TXT));
  3940.  
  3941.     if(OpenDevice("console.device",CONU_LIBRARY,ConsoleRequest,0))
  3942.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_CONSOLE_DEVICE_TXT));
  3943.  
  3944.     ConsoleDevice = &ConsoleRequest -> io_Device -> dd_Library;
  3945.  
  3946.     if(!(FakeInputEvent = (struct InputEvent *)AllocVecPooled(sizeof(struct InputEvent),MEMF_ANY|MEMF_CLEAR)))
  3947.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_INPUTEVENT_TXT));
  3948.  
  3949.     FakeInputEvent -> ie_Class = IECLASS_RAWKEY;
  3950.  
  3951.     if(!(MacroKeys = (struct MacroKeys *)AllocVecPooled(sizeof(struct MacroKeys),MEMF_ANY|MEMF_CLEAR)))
  3952.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACROKEYS_TXT));
  3953.  
  3954.     if(!(CursorKeys = (struct CursorKeys *)AllocVecPooled(sizeof(struct CursorKeys),MEMF_ANY|MEMF_CLEAR)))
  3955.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CURSORKEYS_TXT));
  3956.  
  3957.     ResetCursorKeys(CursorKeys);
  3958.  
  3959.         /* Set up the attention buffers. */
  3960.  
  3961.     if(!(AttentionBuffers[0] = (STRPTR)AllocVecPooled(SCAN_COUNT * 260,MEMF_ANY|MEMF_CLEAR)))
  3962.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SEQUENCE_ATTENTION_INFO_TXT));
  3963.  
  3964.     for(i = 1 ; i < SCAN_COUNT ; i++)
  3965.         AttentionBuffers[i] = &AttentionBuffers[i - 1][260];
  3966.  
  3967.         /* Obtain the default environment storage
  3968.          * path.
  3969.          */
  3970.  
  3971.     if(!ConfigPath)
  3972.     {
  3973.         ConfigPath = PathBuffer;
  3974.  
  3975.         if(!GetEnvDOS("TERMCONFIGPATH",PathBuffer))
  3976.         {
  3977.             if(!GetEnvDOS("TERMPATH",PathBuffer))
  3978.             {
  3979.                 APTR LastPtr = ThisProcess -> pr_WindowPtr;
  3980.                 BPTR FileLock;
  3981.  
  3982.                 strcpy(PathBuffer,"TERM:config");
  3983.  
  3984.                 ThisProcess -> pr_WindowPtr = (APTR)-1;
  3985.  
  3986.                 if(FileLock = Lock("TERM:",ACCESS_READ))
  3987.                     UnLock(FileLock);
  3988.                 else
  3989.                 {
  3990.                     FileLock = DupLock(ThisProcess-> pr_HomeDir);
  3991.  
  3992.                         /* Create TERM: assignment referring to
  3993.                          * the directory `term' was loaded from.
  3994.                          */
  3995.  
  3996.                     if(!AssignLock("TERM",FileLock))
  3997.                         UnLock(FileLock);
  3998.                 }
  3999.  
  4000.                 if(!(FileLock = Lock(PathBuffer,ACCESS_READ)))
  4001.                     FileLock = CreateDir(PathBuffer);
  4002.  
  4003.                 if(FileLock)
  4004.                     UnLock(FileLock);
  4005.  
  4006.                 ThisProcess -> pr_WindowPtr = LastPtr;
  4007.             }
  4008.         }
  4009.     }
  4010.     else
  4011.     {
  4012.         if(GetFileSize(ConfigPath))
  4013.         {
  4014.             STRPTR Index;
  4015.  
  4016.             strcpy(PathBuffer,ConfigPath);
  4017.  
  4018.             Index = PathPart(PathBuffer);
  4019.  
  4020.             *Index = 0;
  4021.  
  4022.             ConfigFileName = ConfigPath;
  4023.  
  4024.             ConfigPath = PathBuffer;
  4025.         }
  4026.     }
  4027.  
  4028.         /* Check for proper assignment path if necessary. */
  4029.  
  4030.         if(!Strnicmp(ConfigPath,"TERM:",5))
  4031.         {
  4032.             APTR OldPtr = ThisProcess -> pr_WindowPtr;
  4033.             BPTR DirLock;
  4034.  
  4035.             /* Block dos requesters. */
  4036.  
  4037.             ThisProcess -> pr_WindowPtr = (APTR)-1;
  4038.  
  4039.             /* Try to get a lock on `TERM:' assignment. */
  4040.  
  4041.         if(DirLock = Lock("TERM:",ACCESS_READ))
  4042.             UnLock(DirLock);
  4043.         else
  4044.         {
  4045.                 /* Clone current directory lock. */
  4046.  
  4047.             DirLock = DupLock(ThisProcess-> pr_CurrentDir);
  4048.  
  4049.                 /* Create TERM: assignment referring to
  4050.                  * current directory.
  4051.                  */
  4052.  
  4053.             if(!AssignLock("TERM",DirLock))
  4054.                 UnLock(DirLock);
  4055.         }
  4056.  
  4057.         ThisProcess -> pr_WindowPtr = OldPtr;
  4058.         }
  4059.  
  4060.         /* Create proper path names. */
  4061.  
  4062.     if(ConfigFileName)
  4063.     {
  4064.         if(!GetFileSize(ConfigFileName))
  4065.             ConfigFileName = NULL;
  4066.     }
  4067.  
  4068.     if(!ConfigFileName)
  4069.     {
  4070.         strcpy(LastConfig,ConfigPath);
  4071.  
  4072.         AddPart(LastConfig,"term_preferences.iff",MAX_FILENAME_LENGTH);
  4073.  
  4074.         if(!GetFileSize(LastConfig))
  4075.         {
  4076.             strcpy(LastConfig,ConfigPath);
  4077.  
  4078.             AddPart(LastConfig,"term.prefs",MAX_FILENAME_LENGTH);
  4079.         }
  4080.     }
  4081.     else
  4082.         strcpy(LastConfig,ConfigFileName);
  4083.  
  4084.     strcpy(DefaultPubScreenName,"Workbench");
  4085.  
  4086.         /* Create both configuration buffers. */
  4087.  
  4088.     if(!(Config = CreateConfiguration(TRUE)))
  4089.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_PRIMARY_CONFIG_TXT));
  4090.  
  4091.     if(!(PrivateConfig = CreateConfiguration(TRUE)))
  4092.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_SECONDARY_CONFIG_TXT));
  4093.  
  4094.     ResetConfig(Config,ConfigPath);
  4095.  
  4096.         /* Read some more environment variables. */
  4097.  
  4098.     if(!WindowName[0])
  4099.     {
  4100.         if(!GetEnvDOS("TERMWINDOW",WindowName))
  4101.             strcpy(WindowName,"CON:0/11//100/term Output Window/CLOSE/SCREEN %s");
  4102.     }
  4103.  
  4104.     GetEnvDOS("EDITOR",Config -> PathConfig -> Editor);
  4105.  
  4106.         /* Look for the default configuration file. */
  4107.  
  4108.     if(!ReadConfig(LastConfig,Config))
  4109.     {
  4110.         ResetConfig(Config,ConfigPath);
  4111.  
  4112.         Initializing = TRUE;
  4113.  
  4114.         LoadColours = TRUE;
  4115.     }
  4116.     else
  4117.     {
  4118.         switch(Config -> ScreenConfig -> ColourMode)
  4119.         {
  4120.             case COLOUR_EIGHT:
  4121.  
  4122.                 CopyMem(Config -> ScreenConfig -> Colours,ANSIColours,16 * sizeof(UWORD));
  4123.                 break;
  4124.  
  4125.             case COLOUR_SIXTEEN:
  4126.  
  4127.                 CopyMem(Config -> ScreenConfig -> Colours,EGAColours,16 * sizeof(UWORD));
  4128.                 break;
  4129.  
  4130.             case COLOUR_AMIGA:
  4131.  
  4132.                 CopyMem(Config -> ScreenConfig -> Colours,DefaultColours,16 * sizeof(UWORD));
  4133.                 break;
  4134.  
  4135.             case COLOUR_MONO:
  4136.  
  4137.                 CopyMem(Config -> ScreenConfig -> Colours,AtomicColours,16 * sizeof(UWORD));
  4138.                 break;
  4139.         }
  4140.  
  4141.         if(Config -> ScreenConfig -> ColourMode == COLOUR_AMIGA)
  4142.             Initializing = FALSE;
  4143.         else
  4144.             Initializing = TRUE;
  4145.     }
  4146.  
  4147.     if(UseNewDevice)
  4148.         strcpy(Config -> SerialConfig -> SerialDevice,NewDevice);
  4149.  
  4150.     if(UseNewUnit)
  4151.         Config -> SerialConfig -> UnitNumber = NewUnit;
  4152.  
  4153.     if(Config -> MiscConfig -> OpenFastMacroPanel)
  4154.         HadFastMacros = TRUE;
  4155.  
  4156.     strcpy(LastPhone,    Config -> PathConfig -> DefaultStorage);
  4157.     AddPart(LastPhone,    "term_phonebook.iff",MAX_FILENAME_LENGTH);
  4158.  
  4159.     if(!GetFileSize(LastPhone))
  4160.     {
  4161.         strcpy(LastPhone,    Config -> PathConfig -> DefaultStorage);
  4162.         AddPart(LastPhone,    "phonebook.prefs",MAX_FILENAME_LENGTH);
  4163.     }
  4164.  
  4165.     strcpy(LastKeys,    Config -> PathConfig -> DefaultStorage);
  4166.     AddPart(LastKeys,    "term_hotkeys.iff",MAX_FILENAME_LENGTH);
  4167.  
  4168.     if(!GetFileSize(LastKeys))
  4169.     {
  4170.         strcpy(LastKeys,    Config -> PathConfig -> DefaultStorage);
  4171.         AddPart(LastKeys,    "hotkeys.prefs",MAX_FILENAME_LENGTH);
  4172.     }
  4173.  
  4174.     strcpy(LastSpeech,    Config -> PathConfig -> DefaultStorage);
  4175.     AddPart(LastSpeech,    "term_speech.iff",MAX_FILENAME_LENGTH);
  4176.  
  4177.     if(!GetFileSize(LastSpeech))
  4178.     {
  4179.         strcpy(LastSpeech,    Config -> PathConfig -> DefaultStorage);
  4180.         AddPart(LastSpeech,    "speech.prefs",MAX_FILENAME_LENGTH);
  4181.     }
  4182.  
  4183.     strcpy(LastFastMacros,    Config -> PathConfig -> DefaultStorage);
  4184.     AddPart(LastFastMacros,    "term_fastmacros.iff",MAX_FILENAME_LENGTH);
  4185.  
  4186.     if(!GetFileSize(LastFastMacros))
  4187.     {
  4188.         strcpy(LastFastMacros,    Config -> PathConfig -> DefaultStorage);
  4189.         AddPart(LastFastMacros,    "fastmacros.prefs",MAX_FILENAME_LENGTH);
  4190.     }
  4191.  
  4192.     if(Config -> FileConfig -> MacroFileName[0])
  4193.         strcpy(LastMacros,Config -> FileConfig -> MacroFileName);
  4194.     else
  4195.     {
  4196.         strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4197.         AddPart(LastMacros,    "term_macros.iff",MAX_FILENAME_LENGTH);
  4198.  
  4199.         if(!GetFileSize(LastMacros))
  4200.         {
  4201.             strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4202.             AddPart(LastMacros,    "macros.prefs",MAX_FILENAME_LENGTH);
  4203.  
  4204.             if(!GetFileSize(LastMacros))
  4205.             {
  4206.                 strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4207.                 AddPart(LastMacros,    "functionkeys.prefs",MAX_FILENAME_LENGTH);
  4208.             }
  4209.         }
  4210.     }
  4211.  
  4212.     strcpy(LastSound,    Config -> PathConfig -> DefaultStorage);
  4213.     AddPart(LastSound,    "sound.prefs",MAX_FILENAME_LENGTH);
  4214.  
  4215.         /* Load the keyboard macros. */
  4216.  
  4217.     if(!LoadMacros(LastMacros,MacroKeys))
  4218.         ResetMacroKeys(MacroKeys);
  4219.  
  4220.     if(Config -> FileConfig -> CursorFileName[0])
  4221.         strcpy(LastCursorKeys,Config -> FileConfig -> CursorFileName);
  4222.     else
  4223.     {
  4224.         strcpy(LastCursorKeys,    Config -> PathConfig -> DefaultStorage);
  4225.         AddPart(LastCursorKeys,    "cursorkeys.prefs",MAX_FILENAME_LENGTH);
  4226.     }
  4227.  
  4228.         /* Load the cursor keys. */
  4229.  
  4230.     if(!ReadIFFData(LastCursorKeys,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  4231.         ResetCursorKeys(CursorKeys);
  4232.  
  4233.         /* Load the sound settings. */
  4234.  
  4235.     memset(&SoundConfig,0,sizeof(struct SoundConfig));
  4236.  
  4237.     SoundConfig . Volume = 100;
  4238.  
  4239.     if(!ReadIFFData(LastSound,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  4240.         strcpy(SoundConfig . BellFile,Config -> TerminalConfig -> BeepFileName);
  4241.  
  4242.         /* Initialize the sound support routines. */
  4243.  
  4244.     SoundInit();
  4245.  
  4246.         /* Are we to load the translation tables? */
  4247.  
  4248.     strcpy(LastTranslation,Config -> FileConfig -> TranslationFileName);
  4249.  
  4250.     if(Config -> FileConfig -> TranslationFileName[0])
  4251.     {
  4252.         if(SendTable = AllocTranslationTable())
  4253.         {
  4254.             if(ReceiveTable = AllocTranslationTable())
  4255.             {
  4256.                 if(!LoadTranslationTables(Config -> FileConfig -> TranslationFileName,SendTable,ReceiveTable))
  4257.                 {
  4258.                     FreeTranslationTable(SendTable);
  4259.  
  4260.                     SendTable = NULL;
  4261.  
  4262.                     FreeTranslationTable(ReceiveTable);
  4263.  
  4264.                     ReceiveTable = NULL;
  4265.                 }
  4266.                 else
  4267.                 {
  4268.                     if(IsStandardTable(SendTable) && IsStandardTable(ReceiveTable))
  4269.                     {
  4270.                         FreeTranslationTable(SendTable);
  4271.  
  4272.                         SendTable = NULL;
  4273.  
  4274.                         FreeTranslationTable(ReceiveTable);
  4275.  
  4276.                         ReceiveTable = NULL;
  4277.                     }
  4278.                 }
  4279.             }
  4280.             else
  4281.             {
  4282.                 FreeTranslationTable(SendTable);
  4283.  
  4284.                 SendTable = NULL;
  4285.             }
  4286.         }
  4287.     }
  4288.  
  4289.     SendSetup();
  4290.  
  4291.     ConOutputUpdate();
  4292.  
  4293.         /* Load the fast! macro settings. */
  4294.  
  4295.     LoadFastMacros(LastFastMacros);
  4296.  
  4297.         /* Load the speech settings. */
  4298.  
  4299.     if(!ReadIFFData(LastSpeech,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  4300.     {
  4301.         SpeechConfig . Rate        = DEFRATE;
  4302.         SpeechConfig . Pitch        = DEFPITCH;
  4303.         SpeechConfig . Frequency    = DEFFREQ;
  4304.         SpeechConfig . Volume        = DEFVOL;
  4305.         SpeechConfig . Sex        = DEFSEX;
  4306.         SpeechConfig . Enabled        = FALSE;
  4307.     }
  4308.  
  4309.         /* Load the hotkey settings. */
  4310.  
  4311.     if(!LoadHotkeys(LastKeys,&Hotkeys))
  4312.     {
  4313.         strcpy(Hotkeys . termScreenToFront,    "lshift rshift return");
  4314.         strcpy(Hotkeys . BufferScreenToFront,    "control rshift return");
  4315.         strcpy(Hotkeys . SkipDialEntry,        "control lshift rshift return");
  4316.         strcpy(Hotkeys . AbortARexx,        "lshift rshift escape");
  4317.  
  4318.         Hotkeys . CommodityPriority    = 0;
  4319.         Hotkeys . HotkeysEnabled    = TRUE;
  4320.     }
  4321.  
  4322.         /* Initialize the data flow parser. */
  4323.  
  4324.     FlowInit(TRUE);
  4325.  
  4326.         /* Set up the edit list labels for the phonebook. */
  4327.  
  4328.     if(!(EditList = (struct List *)AllocVecPooled(sizeof(struct List),MEMF_ANY)))
  4329.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4330.  
  4331.     NewList(EditList);
  4332.  
  4333.     if(!(EditLabels = (STRPTR *)AllocVecPooled(sizeof(STRPTR) * (MSG_PHONEPANEL_RATES_TXT - MSG_PHONEPANEL_SERIAL_TXT + 1),MEMF_ANY | MEMF_CLEAR)))
  4334.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4335.  
  4336.     for(i = MSG_PHONEPANEL_SERIAL_TXT ; i <= MSG_PHONEPANEL_RATES_TXT ; i++)
  4337.     {
  4338.         if(Node = (struct Node *)AllocVecPooled(sizeof(struct Node) + strlen(LocaleString(i)) + 2,MEMF_ANY))
  4339.         {
  4340.             EditLabels[i - MSG_PHONEPANEL_SERIAL_TXT] = Node -> ln_Name = (STRPTR)(Node + 1);
  4341.  
  4342.             Node -> ln_Name[0] = ' ';
  4343.  
  4344.             strcpy(&Node -> ln_Name[1],LocaleString(i));
  4345.  
  4346.             AddTail(EditList,Node);
  4347.         }
  4348.         else
  4349.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4350.     }
  4351.  
  4352.         /* Set up parsing jump tables. */
  4353.  
  4354.     if(!(SpecialTable = (JUMP *)AllocVecPooled(256 * sizeof(JUMP),MEMF_CLEAR | MEMF_ANY)))
  4355.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4356.  
  4357.     for(i = 0 ; i < sizeof(SpecialKeys) / sizeof(struct SpecialKey) ; i++)
  4358.         SpecialTable[SpecialKeys[i] . Key] = (JUMP)SpecialKeys[i] . Routine;
  4359.  
  4360.     if(!(AbortTable = (JUMP *)AllocVecPooled(256 * sizeof(JUMP),MEMF_ANY)))
  4361.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4362.  
  4363.     for(i = 0 ; i < 256 ; i++)
  4364.     {
  4365.         switch(AbortMap[i])
  4366.         {
  4367.             case 0:    AbortTable[i] = (JUMP)ParseCode;
  4368.                 break;
  4369.  
  4370.             case 1:    AbortTable[i] = (JUMP)DoCancel;
  4371.                 break;
  4372.  
  4373.             case 2:    AbortTable[i] = (JUMP)DoNewEsc;
  4374.                 break;
  4375.  
  4376.             case 3:    AbortTable[i] = (JUMP)DoNewCsi;
  4377.                 break;
  4378.         }
  4379.     }
  4380.  
  4381.         /* Create all generic lists. */
  4382.  
  4383.     for(i = GLIST_UPLOAD ; i < GLIST_COUNT ; i++)
  4384.     {
  4385.         if(!(GenericListTable[i] = CreateGenericList()))
  4386.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4387.     }
  4388.  
  4389.         /* Load the trap settings. */
  4390.  
  4391.     strcpy(LastTraps,    Config -> PathConfig -> DefaultStorage);
  4392.     AddPart(LastTraps,    "trap.prefs",MAX_FILENAME_LENGTH);
  4393.  
  4394.     WatchTraps = TRUE;
  4395.  
  4396.     LoadTraps(LastTraps,GenericListTable[GLIST_TRAP]);
  4397.  
  4398.         /* Create the special event queue. */
  4399.  
  4400.     if(!(SpecialQueue = CreateMsgQueue(NULL,0)))
  4401.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4402.  
  4403.         /* Set up the serial driver. */
  4404.  
  4405.     if(Error = CreateSerial())
  4406.     {
  4407.         MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  4408.  
  4409.         DeleteSerial();
  4410.     }
  4411.     else
  4412.     {
  4413.         if(SerialMessage)
  4414.         {
  4415.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  4416.  
  4417.             SerialMessage = NULL;
  4418.         }
  4419.     }
  4420.  
  4421.         /* Get a signal bit. */
  4422.  
  4423.     if((CheckBit = AllocSignal(-1)) == -1)
  4424.         return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_CHECK_SIGNAL_TXT));
  4425.  
  4426.     if(!(TimePort = (struct MsgPort *)CreateMsgPort()))
  4427.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  4428.  
  4429.     if(!(TimeRequest = (struct timerequest *)CreateIORequest(TimePort,sizeof(struct timerequest))))
  4430.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_IOREQUEST_TXT));
  4431.  
  4432.     if(OpenDevice("timer.device",UNIT_VBLANK,TimeRequest,0))
  4433.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_TIMER_DEVICE_TXT));
  4434.  
  4435.     TimerBase = &TimeRequest -> tr_node . io_Device -> dd_Library;
  4436.  
  4437.         /* Add the global term port. */
  4438.  
  4439.     if(!TermPort)
  4440.     {
  4441.         if(!(TermPort = (struct TermPort *)AllocVec(sizeof(struct TermPort) + 11,MEMF_PUBLIC|MEMF_CLEAR)))
  4442.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_GLOBAL_PORT_TXT));
  4443.         else
  4444.         {
  4445.             NewList(&TermPort -> ExecNode . mp_MsgList);
  4446.  
  4447.             InitSemaphore(&TermPort -> OpenSemaphore);
  4448.  
  4449.             TermPort -> ExecNode . mp_Flags            = PA_IGNORE;
  4450.             TermPort -> ExecNode . mp_Node . ln_Name    = (char *)(TermPort + 1);
  4451.  
  4452.             strcpy(TermPort -> ExecNode . mp_Node . ln_Name,"term Port");
  4453.  
  4454.             AddPort(&TermPort -> ExecNode);
  4455.         }
  4456.     }
  4457.  
  4458.         /* Keep another term task from removing the port. */
  4459.  
  4460.     TermPort -> HoldIt = TRUE;
  4461.  
  4462.         /* Install a new term process. */
  4463.  
  4464.     ObtainSemaphore(&TermPort -> OpenSemaphore);
  4465.  
  4466.     TermPort -> OpenCount++;
  4467.  
  4468.     TermPort -> HoldIt = FALSE;
  4469.  
  4470.     TermID = TermPort -> ID++;
  4471.  
  4472.     ReleaseSemaphore(&TermPort -> OpenSemaphore);
  4473.  
  4474.         /* Set up the ID string. */
  4475.  
  4476.     if(TermID)
  4477.         SPrintf(TermIDString,"TERM.%ld",TermID);
  4478.     else
  4479.         strcpy(TermIDString,"TERM");
  4480.  
  4481.     if(RexxPortName[0])
  4482.     {
  4483.         WORD i;
  4484.  
  4485.         for(i = 0 ; i < strlen(RexxPortName) ; i++)
  4486.             RexxPortName[i] = ToUpper(RexxPortName[i]);
  4487.  
  4488.         if(FindPort(RexxPortName))
  4489.             RexxPortName[0] = 0;
  4490.     }
  4491.  
  4492.     if(!RexxPortName[0])
  4493.         strcpy(RexxPortName,TermIDString);
  4494.  
  4495.         /* Install the hotkey handler. */
  4496.  
  4497.     SetupCx();
  4498.  
  4499.         /* Allocate the first few lines for the display buffer. */
  4500.  
  4501.     if(!CreateBuffer())
  4502.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_VIEW_BUFFER_TXT));
  4503.  
  4504.     if(!(XprIO = (struct XPR_IO *)AllocVec(sizeof(struct XPR_IO),MEMF_ANY|MEMF_CLEAR)))
  4505.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_PROTOCOL_BUFFER_TXT));
  4506.  
  4507.         /* Set up the external emulation macro data. */
  4508.  
  4509.     if(!(XEM_MacroKeys = (struct XEmulatorMacroKey *)AllocVecPooled((2 + 10 * 4) * sizeof(struct XEmulatorMacroKey),MEMF_ANY|MEMF_CLEAR)))
  4510.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACRO_KEY_DATA_TXT));
  4511.  
  4512.     strcpy(LastXprLibrary,Config -> TransferConfig -> DefaultLibrary);
  4513.  
  4514.     ProtocolSetup(FALSE);
  4515.  
  4516.         /* Load a keymap file if required. */
  4517.  
  4518.     if(Config -> TerminalConfig -> KeyMapFileName[0])
  4519.         KeyMap = LoadKeyMap(Config -> TerminalConfig -> KeyMapFileName);
  4520.  
  4521.     if(!(TermRexxPort = (struct MsgPort *)CreateMsgPort()))
  4522.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  4523.  
  4524.         /* If rexxsyslib.library opens cleanly it's time for
  4525.          * us to create the background term Rexx server.
  4526.          */
  4527.  
  4528.     if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  4529.     {
  4530.             /* Create a background process handling the
  4531.              * rexx messages asynchronously.
  4532.              */
  4533.  
  4534.         Forbid();
  4535.  
  4536.         if(RexxProcess = (struct Process *)CreateNewProcTags(
  4537.             NP_Entry,    RexxServer,
  4538.             NP_Name,    "term Rexx Process",
  4539.             NP_Priority,    5,
  4540.             NP_StackSize,    8192,
  4541.             NP_WindowPtr,    -1,
  4542.         TAG_END))
  4543.         {
  4544.             ClrSignal(SIG_HANDSHAKE);
  4545.  
  4546.             Wait(SIG_HANDSHAKE);
  4547.         }
  4548.  
  4549.         Permit();
  4550.  
  4551.         if(!RexxProcess)
  4552.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_AREXX_PROCESS_TXT));
  4553.     }
  4554.  
  4555.         /* Install the public screen name, assumes that the user
  4556.          * wants the window to be opened on the screen, rather than
  4557.          * opening a custom screen.
  4558.          */
  4559.  
  4560.     if(SomePubScreenName[0])
  4561.     {
  4562.         strcpy(Config -> ScreenConfig -> PubScreenName,SomePubScreenName);
  4563.  
  4564.         Config -> ScreenConfig -> Blinking    = FALSE;
  4565.         Config -> ScreenConfig -> FasterLayout    = FALSE;
  4566.         Config -> ScreenConfig -> UseWorkbench    = TRUE;
  4567.  
  4568.         SomePubScreenName[0] = 0;
  4569.     }
  4570.  
  4571.     CreateQueueProcess();
  4572.  
  4573.     Forbid();
  4574.  
  4575.     RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Name = RexxPortName;
  4576.     RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Pri  = -127;
  4577.  
  4578.     AddSemaphore(&RendezvousSemaphore);
  4579.  
  4580.     Permit();
  4581.  
  4582.     if(DoIconify)
  4583.         return(NULL);
  4584.     else
  4585.     {
  4586.             /* Create the whole display. */
  4587.  
  4588.         if(Result = CreateDisplay(TRUE))
  4589.             return(Result);
  4590.         else
  4591.         {
  4592.             PubScreenStuff();
  4593.  
  4594.             return(NULL);
  4595.         }
  4596.     }
  4597. }
  4598.